如果你不嫌麻烦的话。。。
#include<iostream>
using namespace std;
int main()
{
char str1,str2,str3;
while(cin>>str1>>str2>>str3)
{
if(str1>str2&&str2>str3)
{
cout<<str3<<" "<<str2<<" "<<str1<<endl;
}
else if(str1>str3&&str3>str2)
{
cout<<str2<<" "<<str3<<" "<<str1<<endl;
}
else if(str2>str3&&str3>str1)
{
cout<<str1<<" "<<str3<<" "<<str2<<endl;
}
else if(str2>str1&&str1>str3)
{
cout<<str3<<" "<<str1<<" "<<str2<<endl;
}
else if(str3>str1&&str1>str2)
{
cout<<str2<<" "<<str1<<" "<<str3<<endl;
}
else
{
cout<<str1<<" "<<str2<<" "<<str3<<endl;
}
}
return 0;
}
还可以这样:
#include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
char n[4];
while (cin >> n)
{
if (n[0] > n[1]) swap(n[0], n[1]);
if (n[1] > n[2]) swap(n[1], n[2]);
if (n[0] > n[1]) swap(n[0], n[1]);
cout << n[0] << ' ' << n[1] << ' ' << n[2] << endl;
}
return 0;
}