河南省之6 奇怪的排序

 1 #include<stdio.h>
 2 #include<algorithm>
 3 #include<stdlib.h>
 4 using namespace std;
 5 
 6 typedef struct 
 7 {
 8     int x;
 9     int y;
10 }node;
11 
12 int fun(int a)
13 {
14     int t=0;
15     while(a)
16     {
17         t=t*10+a%10;
18         a=a/10;
19     }
20     return t;
21 }
22 
23 int cmp(const node a,const node b)
24 {
25     return a.y<b.y;
26 }
27 
28 int main()
29 {
30     int i,j,n,m,t;
31     node a[55];
32     scanf("%d",&t);
33     while(t--)
34     {
35         scanf("%d%d",&n,&m);
36         for(i=n,j=0;i<=m;i++,j++)
37         {    
38             a[j].x=i;
39             a[j].y=fun(i);
40         }
41         sort(a,a+j,cmp);
42         for(i=0;i<j-1;i++)
43             printf("%d ",a[i].x);
44         printf("%d\n",a[i].x);
45     }
46     return 0;
47 }

 

posted @ 2013-04-06 10:36  萧凡客  阅读(226)  评论(0编辑  收藏  举报