1336 - C语言程序设计教程(第三版)课后习题10.2
时间限制 : 1 秒
内存限制 : 128 MB
输入三个字符串,按由小到大的顺序输出
题目输入
3行字符串
题目输出
按照从小到大输出成3行
输入/输出样例
输入格式
cde afg abc
输出格式
abc afg cde
C++解答
#include<iostream> #include<cstdio> #include<cstring> using namespace std; void swap(char *p,char *q) { char str[50]; strcpy(str,p); strcpy(p,q); strcpy(q,str); } int main() { char s1[50],s2[50],s3[50]; char *p1=s1,*p2=s2,*p3=s3; gets(p1); gets(p2); gets(p3); if (strcmp(p1,p2)>0) swap(p1,p2); if (strcmp(p1,p3)>0) swap(p1,p3); if (strcmp(p2,p3)>0) swap(p2,p3); printf("%s\n%s\n%s\n",p1,p2,p3); return 0; }