1473: 奇怪的排序
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 109 Solved: 66
SubmitStatusWeb Board
Description
最近,Dr. Kong 新设计一个机器人Bill。这台机器人很聪明,会做许多事情。惟独对自然数的理解与人类不一样,它是从右往左读数。比如,它看到123时,会理解成321。让它比较23与15哪一个大,它说15大。原因是它的大脑会以为是32与51在进行比较。再比如让它比较29与30,它说29大。
给定Bill两个自然数A和B,让它将 [A,B] 区间中的所有数按从小到大排序出来。你会认为它如何排序?
Input
第一行: N 表示有多少组测试数据。
接下来有N行,每一行有两个正整数A B 表示待排序元素的区间范围。
2<=N<=5 1<=A<=B<=200000 B-A<=50。
Output
对于每一行测试数据,输出一行,为所有排好序的元素,元素之间有一个空格。
Sample Input
28 15
22 39
Sample Output
10 8 9 11 12 13 14 15
30 31 22 32 23 33 24 34 25 35 26 36 27 37 28 38 29 39
利用结构体排序:
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; struct note{ int z; int l; }q[55]; bool cmp(note a,note b) { return a.l<b.l; } int main() { int n,a,b,i,k; scanf("%d",&n); while(n--) { memset(q,0,sizeof(q)); scanf("%d%d",&a,&b); for(i=a,k=0;i<=b;i++,k++) { q[k].z=i; int f=i; while(f) { q[k].l=q[k].l*10+f%10; f/=10; } } sort(q,q+k,cmp); for(i=0;i<k;i++) { printf("%d",q[i].z); if(i!=k-1) printf(" "); else printf("\n"); } } return 0; }