0
点赞
收藏
分享

微信扫一扫

奇怪的排序 【简单题】



奇怪的排序


Time Limit: 1 Sec   Memory Limit: 128 MB

Submit: 60  

Solved: 39

[​Submit​​][​Status​​][​Web Board​​]


Description


最近,Dr. Kong 新设计一个机器人Bill。这台机器人很聪明,会做许多事情。惟独对自然数的理解与人类不一样,它是从右往左读数。比如,它看到123时,会理解成321。让它比较23与15哪一个大,它说15大。原因是它的大脑会以为是32与51在进行比较。再比如让它比较29与30,它说29大。

给定Bill两个自然数A和B,让它将 [A,B] 区间中的所有数按从小到大排序出来。你会认为它如何排序?


Input


第一行:        表示有多少组测试数据。

接下来有N行,    每一行有两个正整数A B  表示待排序元素的区间范围。


Output


对于每一行测试数据,输出一行,为所有排好序的元素,元素之间有一个空格。


Sample Input

2

8 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

HINT

2<=N<=5      1<=A<=B<=200000  B-A<=50。


Source


​​第五届河南省大学生程序设计竞赛​​

#include<stdio.h>
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<queue>
#include<stack>
#include<set>
#include<map>

using namespace std;

int t, x;
int n, m;
char q[100000];

struct node
{
int x;
int rx;
}p[10000000];

bool cmp(node a,node b)
{
return a.rx <= b.rx;
}

int main()
{
scanf("%d",&t);
while (t--)
{
scanf("%d%d",&n,&m);
for (int i = n; i <= m; i++)
{
p[i].x = i;
sprintf(q,"%d",i);
int len = strlen(q);
p[i].rx = 0;
for (int j = len - 1; j >= 0; j--)
{
p[i].rx += pow(10,j) * (int )(q[j] - '0');
}
}
sort(p + n, p + m + 1,cmp);
for (int i = n; i <= m; i++)
{
printf("%d", p[i].x);
if (i != m)
printf(" ");
else
printf("\n");
}
}
return 0;
}




举报

相关推荐

0 条评论