定义一个字符串,以输入做为循环条件,使用三个if来排序三个字符
输出时依次输出,在字符间加入空格
...
include<iostream>
using namespace std;
int main()
{
char s[3];
char a;
while (cin >> s)
{
if (s[0] > s[1])
{
a = s[0];
s[0] = s[1];
s[1] = a;
}
if (s[0] > s[2])
{
a = s[0];
s[0] = s[2];
s[2] = s[0];
}
if (s[1] > s[2])
{
a = s[1];
s[1] = s[2];
s[2] = a;
}
for (int i = 0; i < 3; i++)
{
cout << s[i];
if (i == 2)
cout << endl;
else
cout << " ";
}
}
return 0;
}
...
网友评论