HDU 2000 ASCII码排序

http://acm.hdu.edu.cn/showproblem.php?pid=2000

Problem Description
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
 
Input
输入数据有多组,每组占一行,有三个字符组成,之间无空格。
 
Output
对于每组输入数据,输出一行,字符中间用一个空格分开。
 
Sample Input
qwe
asd
zxc
 
Sample Output
e q w
a d s
c x z
 
代码:
#include <bits/stdc++.h>

using namespace std;

char s[111];
int main()
{
    while(scanf("%s",s)!=EOF)
    {
        int len = strlen(s);
        for(int i=0; i<len; i++)
        {
            for(int j=i; j>=1; j--)
            {
                if(s[j]<=s[j-1])
                    swap(s[j],s[j-1]);
            }
        }

        for(int i=0; i<len; i++)
        {
            if(i!=len-1)
                printf("%c ",s[i]);
            else
                printf("%c
",s[i]);
        }
    }
    return 0;
}

  

原文地址:https://www.cnblogs.com/zlrrrr/p/9221815.html