NYOJ 4ASCII码排序

xiaoxiao2021-02-27  183

ASCII码排序

时间限制: 3000 ms  |  内存限制: 65535 KB 描述 输入三个字符(可以重复)后,按各字符的ASCII码从小到大的顺序输出这三个字符。 输入 第一行输入一个数N,表示有N组测试数据。后面的N行输入多组数据,每组输入数据都是占一行,有三个字符组成,之间无空格。 输出 对于每组输入数据,输出一行,字符中间用一个空格分开。 样例输入 2 qwe asd 样例输出 e q w a d s C语言: #include "stdio.h" main() { char a,b,c,d; int i; scanf("%d",&i); getchar(); while(i--) { scanf("%c%c%c",&a,&b,&c); getchar(); if (a>b) {d=a;a=b;b=d;} if (a>c) {d=a;a=c;c=d;} if (b>c) {d=b;b=c;c=d;} printf("%c %c %c\n",a,b,c); } } C++: #include<iostream> #include<string> #include<cstdio> #include<algorithm> using namespace std; int main() { char str[4]; int n,i; cin>>n; cin.get(); while(n--) { scanf("%c%c%c",&str[0],&str[1],&str[2]); cin.get(); sort(str,str+3); for (i=0;i<3;i++) { if (i!=0) cout<<' '<<str[i]; else cout<<str[i]; } cout<<endl; } } 
转载请注明原文地址: https://www.6miu.com/read-15559.html

最新回复(0)