HDOJ 2000-ASCII码排序

    xiaoxiao2021-12-13  20

    Problem Description 输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。

    Input 输入数据有多组,每组占一行,有三个字符组成,之间无空格。

    Output 对于每组输入数据,输出一行,字符中间用一个空格分开。

    Sample Input qwe asd zxc

    Sample Output e q w a d s c x z

    思路: 两两比较,如果前者大于后者 ,交换位置。特别注意,getchar()消去回车符。

    #include "stdio.h" int main() { char a,b,c,d,e,f; while(scanf("%c%c%c",&a,&b,&c)!=EOF) { if(a>b) { d=a; a=b; b=d; } if(b>c) { e=b; b=c; c=e; } if(a>b) { f=a; a=b; b=f; } printf("%c %c %c\n",a,b,c); getchar(); } return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-950301.html

    最新回复(0)