[YTU]_1064 (输入三个字符串,按由小到大的顺序输出)
生活随笔
收集整理的這篇文章主要介紹了
[YTU]_1064 (输入三个字符串,按由小到大的顺序输出)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Description
輸入三個字符串,按由小到大的順序輸出。分別使用指針和引用方式實現兩個排序函數。在主函數中輸入和輸出數據。
Input
3行字符串
Output
按照從小到大輸出成3行。由指針方式實現。 按照從小到大輸出成3行。由引用方式實現。Sample Input
cde afg abcSample Output
abc afg cde abc afg cde#include <iostream> #include <string> #include <cstring> using namespace std; void sort1(char*p11,char*p22,char*p33) {void swap1(char *R,char *r);if(strcmp(p11,p22)>0)swap1(p11,p22);if(strcmp(p11,p33)>0)swap1(p11,p33);if(strcmp(p22,p33)>0)swap1(p22,p33); } void swap1(char *R,char *r) {char temp[100];strcpy(temp,R);strcpy(R,r);strcpy(r,temp); }void sort2(string &r11,string &r22,string &r33) {void swap2(string &,string &);if(r11>r22)swap2(r11,r22);if(r11>r33)swap2(r11,r33);if(r22>r33)swap2(r22,r33); } void swap2(string &R,string &r) {string temp;temp=R;R=r;r=temp; } int main() {void sort1(char *,char *,char *);void sort2(string &,string &,string &);char s1[100],s2[100],s3[100];char *p1,*p2,*p3;string r1,r2,r3;cin>>s1>>s2>>s3;r1=string(s1);r2=string(s2);r3=string(s3);p1=s1;p2=s2;p3=s3;sort1(p1,p2,p3);cout<<s1<<endl<<s2<<endl<<s3<<endl;sort2(r1,r2,r3);cout<<r1<<endl<<r2<<endl<<r3<<endl;return 0; }《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀
總結
以上是生活随笔為你收集整理的[YTU]_1064 (输入三个字符串,按由小到大的顺序输出)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [YTU]_1063 (输入三个整数,按
- 下一篇: [YTU]_2865( 结构体--日期计