Strange sorting time limit: 1000 MS | memory limit: 65535 kb difficulty: 1
-
Description
-
Recently, dr. Kong has designed a new robot, Bill. This robot is very intelligent and will do many things. The understanding of natural numbers is different from that of humans. It reads from right to left. for example, if it sees 123, it will be interpreted as 321. make it bigger than 23 and 15, which is 15. The reason is that its brain will think that it is comparing 32 and 51. For example, if it is compared with 29 and 30, it will say 29 is big.
Given the two natural numbers a and B of Bill, let it sort all the numbers in the [a, B] range in ascending order. How do you think it is sorted?
-
Input
-
Row 1: N indicates the number of groups of test data. (2 <= n <= 5)
Next there are n rows, each row has two positive integers a B represents the range of the elements to be sorted. (1 <= A <= B <= 200000 B-A <= 50)
-
Output
-
For each row of test data, a line is output, which is a space between all elements sorted in order.
-
Sample Input
-
28 1522 39
-
Sample output
-
10 8 9 11 12 13 14 1530 31 22 32 23 33 24 34 25 35 26 36 27 37 28 38 29 39
-
Source
-
Fifth Henan Program Design Competition
-
Uploaded
-
ACM _ Li rubing
The idea is also very simple. We can simply sort the numbers in reverse order and then sort them and output them directly. Some of the Code in reverse order is widely used.
The following is the code;
# Include <iostream> # include <stdio. h ># include <algorithm> using namespace STD; int CMP (int n, int m) // reverse processing of the logarithm {int A = 0, B = 0; while (n! = 0) {A = A * 10 + N % 10; // This method is clever N/= 10;} while (M! = 0) {B = B * 10 + M % 10; M/= 10;} return a <B? 1:0;} int main () {int T, I, j, s [52], a, B; // freopen ("1.txt"," r ", stdin ); // freopen ("2.txt"," W ", stdout); scanf (" % d ", & T); While (t --) {scanf (" % d ", & A, & B); for (I = A, j = 0; I <= B; I ++) s [J ++] = I; sort (S, S + (B-a) + 1, CMP); // sort printf ("% d", s [0]); for (I = 1; I <J; I ++) printf ("% d", s [I]); printf ("\ n");} return 0 ;}