hdu2000 ASCII码排序【C++】

ASCII码排序

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 206054    Accepted Submission(s): 82273


Problem Description
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
 
Input
输入数据有多组,每组占一行,有三个字符组成,之间无空格。
 
Output
对于每组输入数据,输出一行,字符中间用一个空格分开。
 
Sample Input
qwe asd zxc
 
Sample Output
e q w a d s c x z
 1 #include<iostream>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int main()
 6 {
 7     string s("");
 8     char a[10];
 9     while(getline(cin,s))
10     {
11         strcpy(a,s.c_str());
12         sort(a,a+3);
13         for(int i = 0;i < 3;++i)
14         {
15             if(i < 2)
16             {
17                 cout << a[i] << " " ;//不知道为什么不能cout << a[i] + " " ;
18             }
19             else
20             {
21                 cout << a[i] << endl;
22             }
23 
24         }
25     }
26     return 0;
27 }
原文地址:https://www.cnblogs.com/knmxx/p/9277091.html