A-ASCII码排序 HDU - 2000
一道排序题,唯一需要注意的是输出的格式(注意第三个字符后面没有空格)
下面给出两种方法:
1)
#include<stdio.h> int main() { char a,b,c,t; while(scanf("%c%c%c",&a,&b,&c)!=EOF) { getchar();//getchar()是消去每次输入之后的换行符(回车键),不然会导致换行符成为下次程序运行的第一个字符。 if(a>b) {t=a;a=b;b=t;} if(a>c) {t=a;a=c;c=t;} if(b>c) {t=b;b=c;c=t;} printf("%c %c %c\n",a,b,c); } return 0; }
2)
#include<iostream> #include<algorithm> using namespace std; int main() { char a[5]; while(cin>>a) { sort(a,a+3); for(int i=0;i<=1;i++) cout<<a[i]<<" "; cout<<a[2]; cout<<endl; } return 0; }

浙公网安备 33010602011771号