ASCII code sorting
Time Limit:
3000 ms | Memory Limit: 65535 KB |
Difficulty:
2
- describe
- After inputting three characters (which can be repeated), output the three characters in ascending order of their ASCII codes.
- enter
- Enter a number N in the first line, indicating that there are N groups of test data. The following N lines input multiple sets of data, each set of input data occupies one line, consisting of three characters with no spaces in between.
- output
- For each set of input data, output one line, separated by a space between characters.
- sample input
-
2 qwe asd
- Sample output
-
e q w a d s
/** Analysis: sort() function implements sorting from small to large **/
C/C++ code implementation:
#include <iostream> #include <algorithm> #include <cmath> #include <cstring> #include <cstdio> #include <stack> using namespace std; char ch[4]; int main () { int N; scanf ("%d", &N); while (N --) { scanf ("%s", &ch[0]); sort (ch, ch + 3, less<char>()); for (int i = 0; i < 3; ++ i) printf ("%c ", ch[i]); printf ("\n"); } return 0; }