2000:ASCII码排序

Description

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

Input

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

Output

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

Sample Input

 
   
qwe
asd
zxc

Sample Output

 
   
e q w
a d s
c x z

#include<iostream>
#include<string>
using namespace std;
int main(){
	char c[3],t;
	int i=0,j=0;
	while(gets(c)){      //gets(接收一个字符串,可以接受空格并输出,需包含#include<string>;
	                     //当输入的字符串不为空时,循环继续
		for(i=0;i<2;i++)    //冒泡排序
			for(j=i+1;j<3;j++)
				if(c[i]>c[j]){
					t=c[i];c[i]=c[j];c[j]=t;
				}
		cout<<c[0]<<" "<<c[1]<<" "<<c[2]<<endl;
	}
	return 0;
} 
问题:怎样才可以连续输入多组字符,最后再连续输出,而不是像现在这样只能一组一组地操作?

猜你喜欢

转载自blog.csdn.net/gunianshan/article/details/81011268