c语言,c++编程,用if else结构

编写程序,从键盘输入三个大写字母,按照字母顺序输出。如:输入QCG,则输出CGQ

一种很粗糙的实现:

#include <stdio.h>

int main(void){
    char a,b,c;
    

    scanf("%c%c%c",&a,&b,&c);
    
    //算法很粗糙
    //很粗糙的算法,列举a、b、c三个字母不同的排列顺序,然后判断,依次打印。 
    //等号是考虑到三个字母有相等的时候 
    
    if(a<=b&&b<=c)
        printf("%c%c%c",a,b,c); 
    else if(a<=c&&c<=b)
        printf("%c%c%c",a,c,b); 
    else if(c<=a&&a<=b)
        printf("%c%c%c",c,a,b); 
    else if(c<=b&&b<=a)
        printf("%c%c%c",c,b,a); 
    else if(b<=c&&c<=a)
        printf("%c%c%c",b,c,a); 
    else
        printf("%c%c%c",b,a,c); 
        
    
    
    
    return 0;
}

供参考:

#include <stdio.h>
int main()
{
    char a, b, c, t;
    scanf("%c%c%c", &a, &b, &c);
    if (a > b)
    {
        t = a; a = b; b = t;
    }
    if (a > c)
    {
        t = a; a = c; c = t;
    }
    if (b > c)
    {
        t = b; b = c; c = t;
    }
    printf("%c%c%c", a, b, c);
    return 0;
}