游客 Signup | Login
中文 | En

1336 - C语言程序设计教程(第三版)课后习题10.2

输入三个字符串,按由小到大的顺序输出

Input

3行字符串

Output

按照从小到大输出成3行

Examples

Input

cde
afg
abc

Output

abc
afg
cde

Solution 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;
}
Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题