用%*c滤掉回车,ASCII码排序

Problem Description
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
 Input
输入数据有多组,每组占一行,有三个字符组成,之间无空格。         //用%*c滤掉回车
Output
对于每组输入数据,输出一行,字符中间用一个空格分开。printf("... ");
 Sample Input
qwe asd zxc
 Sample Output
e q w
a d s
c x z
code1:
#include <stdio.h>
int main()
{
char a,b,c,tmp;
while(scanf("%c%c%c%*c",&a,&b,&c)!=EOF) //用"%*c"(空字符,不存储字符的字符)滤掉回车
{ if(a>b) tmp=a,a=b,b=tmp; //逗号表达式,简洁
if(a>c) tmp=a,a=c,c=tmp;
if(b>c) tmp=b,b=c,c=tmp;
printf("%c %c %c ",a,b,c);
}
return 0;
}
code2:

#include <stdio.h>

int main()
{
    char a,b,c,tmp;
    while((a=getchar())!=EOF)
    {
        b=getchar();
        c=getchar();
        getchar();    //在录入c后用getchar()滤掉回车
        if(a>b)
        {
            tmp=a;
            a=b;
            b=tmp;
        }
        if(a>c)
        {
            tmp=a;
            a=c;
            c=tmp;
        }
        if(b>c)
        {
            tmp=b;
            b=c;
            c=tmp;
        }
        printf("%c %c %c ",a,b,c);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/gongpulin/p/3870360.html