Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 191438 Accepted Submission(s): 76494
Problem Description
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
Input
输入数据有多组,每组占一行,有三个字符组成,之间无空格。
Output
对于每组输入数据,输出一行,字符中间用一个空格分开。
Sample Input
qwe
asd
zxc
Sample Output
e q w
a d s
c x z
Author
lcy
Source
问题链接:HDU2000 ASCII码排序。
问题简述:参见上述链接。
问题分析:
这个问题几乎没有技术含量,原意是作为C语言程序的练习。
然而,如果用C++语言来编写程序,需要用到哪些技术呢?看了程序才能知道。
程序说明:
先谢了一个C++的版本。用C++的算法函数sort()实现排序真是方便。
为了初学C语言的人,又写了一个C语言的版本,好在是3个数的排序,做起来就简单了。虽说简单,也要做出一个有思想的程序,三个数的排序,程序中用的是冒泡排序的思想,有几人能看得出?
题记:杀鸡也用宰牛刀。
AC的C语言程序如下:
/* HDU2000 ASCII码排序 */
#include <stdio.h>
int main(void)
{
char a, b, c, temp;
while(~scanf("%c%c%c", &a, &b, &c)) {
getchar();
if(a > b) {
temp = a;
a = b;
b = temp;
}
if(b > c) {
temp = b;
b = c;
c = temp;
}
if(a > b) {
temp = a;
a = b;
b = temp;
}
printf("%c %c %c\n", a, b, c);
}
return 0;
}
AC的C++语言程序如下:
/* HDU2000 ASCII码排序 */
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int N = 3;
int main()
{
string s;
while(getline(cin, s)) {
sort(s.begin(), s.end());
for(int i=0; i<N; i++) {
if(i != 0)
cout << " ";
cout << s[i];
}
cout << endl;
}
return 0;
}
AC的C++语言程序如下:
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
char c[3];
while(scanf("%c%c%c", &c[0], &c[1], &c[2]) != EOF) {
getchar();
sort(c, c + 3);
printf("%c %c %c\n", c[0], c[1], c[2]);
}
return 0;
}