ACM训练题6

ASCII码排序

Problem Description

INPUT

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

OUTPUT

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

问题连接:https://vjudge.net/problem/hdu-2000

AC代码如下:

#include <iostream>
using namespace std;
int main()
{
	char s[1000] = { 0 };
	char a, b, c, t = {0};
	int i = 0;
	while (cin >> a >> b >> c)
	{
		a > b ? t = a, a = b, b = t : t = t;
		b > c ? t = b, b = c, c = t : t = t;
		a > b ? t = a, a = b, b = t : t = t;
		s[i] = a; s[i + 1] = b; s[i + 2] = c;
		i += 3;
	}
	for (int j = 0; j < i; j += 3)
		cout << s[j] << " " << s[j + 1] << " " << s[j + 2] << endl;
	

}

猜你喜欢

转载自blog.csdn.net/weixin_43966635/article/details/84854602