HDU - 2000 ASCII码排序

ASCII码排序 HDU - 2000

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

#include<stdio.h>
int main()
{
    char a[3],temp;//每组是三个字符,所以定义三个就够了
    while (scanf("%s",&a)!=EOF)//不能分别读取,这样会出现RE
     {
        if(a[0]>a[2])
        {
            temp=a[0];
            a[0]=a[2];
             a[2]=temp;
         }
         if(a[1]>a[2])
         {
             temp= a[1];
             a[1]=a[2];
            a[2]=temp;
        }

         if(a[0]>a[1])
         {
             temp=a[1];
             a[1]=a[0];
            a[0]=temp;
         }//以上进行比大小
        printf("%c %c %c\n",a[0],a[1],a[2]);输出
     }
 }

猜你喜欢

转载自blog.csdn.net/qq_43382350/article/details/84963250