Text Reverse
Time limit 1000 ms
Memory limit 32768 kB
OS Windows
Source C语言程序设计练习(一)
Problem Description
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
Input
输入数据有多组,每组占一行,有三个字符组成,之间无空格。
Output
对于每组输入数据,输出一行,字符中间用一个空格分开。
Sample Input
qwe
asd
zxc
Sample Output
e q w
a d s
c x z
问题链接:HDU - 2000
问题简述:
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
问题分析:
使用数组以及冒泡排序法
程序说明:
建立一个内存为4的字符串数组来记录字符串,通过冒泡排序法将字符按照ASCII码从小到大排序。
#include<iostream>
using namespace std;
int main()
{
char s[4],t;
int i, j;
while (cin >>s)
{
for (i = 0; i < 2; i++)
{
for (j = 0; j <2-i; j++)
{
if (s[j] > s[j + 1])
{
t = s[j + 1];
s[j + 1] = s[j];
s[j] = t;
}
}
}
cout << s[0] << " "<< s[1] << " " << s[2] <<endl ;
}
return 0;
}