ACM第六题

题目:输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。

    Input
    输入数据有多组,每组占一行,有三个字符组成,之间无空格。

    Output
    对于每组输入数据,输出一行,字符中间用一个空格分开。

#include
using namespace std;
int main()
{
 int i, j;
 char a[3], temp;
 while (cin >> a)
 {
  for (j = 0; j < 2; j++)
   for (i = j; i < 2; i++)
    if (a[j] > a[i + 1])
    {
     temp = a[j];
     a[j] = a[i + 1];
     a[i + 1] = temp;
    }
  for (i = 0; i < 3; i++)
  {
   cout << a[i];
   if (i <= 1)
    cout <<" ";
  }
  cout << endl;
 }
}

猜你喜欢

转载自blog.csdn.net/qq_20618369/article/details/84888769