问题 D: C语言10.15——输入3个字符串,按从小到大的顺序输出。要求使用指针的方法进行处理。

 1 #include <iostream>
 2 #include <cstring>
 3 using namespace std;
 4 void strswap(char *&p,char *&q){
 5     char *temp;
 6     temp=p;
 7     p=q;
 8     q=temp;
 9 }
10 int main(){
11     #ifdef ONLINE_JUDGE
12     #else
13         freopen("in.txt","r",stdin);
14     #endif
15     char a[3][20],*p[3];
16     for(int i=0;i<3;i++){
17         cin>>a[i];//或cin.getline(a[i],20);
18         p[i]=a[i];
19     }
20     if(strcmp(p[0],p[1])>0) strswap(p[0],p[1]);
21     if(strcmp(p[0],p[2])>0) strswap(p[0],p[2]);
22     if(strcmp(p[1],p[2])>0) strswap(p[1],p[2]);
23     puts(p[0]);
24     puts(p[1]);
25     cout<<p[2];
26     return 0;    
27 } 
原文地址:https://www.cnblogs.com/gentlebreeze/p/14276698.html