#include<stdio.h> #include<iostream> using namespace std; int main() { char a,b,c,temp; while(cin>>a>>b>>c) { if(a>b) { temp=a; a=b; b=temp; } if(a>c) { temp=c; c=a; a=temp; } if(b>c) { temp=c; c=b; b=temp; } printf("%c %c %c\n",a,b,c); } }
后来发现纯C语言,后面加个空格吸收符也是可行的
#include<stdio.h> int main() { char a,b,c,temp; while(scanf("%c%c%c",&a,&b,&c)!=EOF) { if(a>b) { temp=a; a=b; b=temp; } if(a>c) { temp=c; c=a; a=temp; } if(b>c) { temp=c; c=b; b=temp; } printf("%c %c %c\n",a,b,c); getchar(); } }
原文:https://www.cnblogs.com/wzmm/p/12455659.html