Strange sorting (hpu1162)
Strange sorting Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 69 Solved: 37
[Submit] [Status] [Web Board] Description
Recently, Dr. Kong has designed a new robot, Bill. This robot is very smart 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 32 and 51 are being compared. Another example is to make it compare 29 and 30, which is 29 in size. 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. Next there are N rows. Each row has two positive integers, a B, representing the range of the elements to be sorted. 2 <= N <= 5 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 Input28 1522 39 Sample Output10 8 9 11 12 13 14 1530 31 22 32 23 33 24 34 25 26 36 27 37 28 38 29 39 HINT
Source
Henan fifth ACM provincial competition T1
#include
int a[200010];int b[200010];int tmp(int a){ int ans=0; while(a) { ans+=ans*10+a%10; a/=10; } return ans;}int main(){int test,n,m,i,j,t;scanf("%d",&test);while(test--) { scanf("%d%d",&n,&m);for(i=n;i<=m;i++) { a[i]=tmp(i);b[i]=i;} for(i=n;i<=m;i++){ for(j=i+1;j<=m;j++){ if(a[i]>a[j]){ t=a[i]; a[i]=a[j]; a[j]=t; t=b[i]; b[i]=b[j]; b[j]=t;}}} printf("%d",b[n]); for(i=n+1;i<=m;i++){ printf(" %d",b[i]); } printf("\n");} return 0;}