本文共 599 字,大约阅读时间需要 1 分钟。
ASCII码排序
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。 Input 输入数据有多组,每组占一行,有三个字符组成,之间无空格。 Output 对于每组输入数据,输出一行,字符中间用一个空格分开。 Sample Input qwe asd zxc Sample Output e q w a d s c x z 问题分析:就是输入多组字符,然后根据ascii码大小排序输出咯 程序分析:检查每组输入的字符,根据ascii码大小排序输出 #include #include #define PI 3.1415927 using namespace std; int main() { char a[4]; while (cin >> a) { int i = 0; while (a[i]) { i++; } for (int ii = 0; ii<i;ii++) { int b = ii; for (int iii = ii; iii<i;iii++) { if (a[b] > a[iii]) b = iii; } int c; c = a[b]; a[b] = a[ii]; a[ii] = c; } for ( int ii = 0;ii<i-1;ii++) cout << a[ii] << " "; cout << a[i - 1] << endl; } }转载地址:http://tgevfk.baihongyu.com/