1002: 奇怪的排序
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 64 Solved: 42
[ 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 表示有多少组测试数据。
接下来有N行, 每一行有两个正整数A B 表示待排序元素的区间范围。
Output
对于每一行测试数据,输出一行,为所有排好序的元素,元素之间有一个空格。
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
HINT
2<=N<=5 1<=A<=B<=200000 B-A<=50。
#include "stack"
#include "cstdio"
#include "iostream"
#include "cmath"
#include "set"
#include "sstream"
#include "cctype"
#include "string"
#include "cstring"
#include "algorithm"
#include "queue"
#include "map"
using namespace std;
#define LL long long
#define inf 0x3f3f3f3f
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
const int M=5000;
struct ss
{
int a;
int b;
}k[100];
int reverse(int number)
{
int tmp=0;
while(number!=0)
{
tmp=(tmp*10 + number%10);
number=number/10;
}
if(number<0)
return (-tmp);
else return tmp;
}
bool cmp(ss x,ss y)
{
return x.b<y.b;
}
int main()
{
int n,m;
int i,j;
cin>>n;
while(n--)
{
int x,y;
m=0;
cin>>x>>y;
for(i=x;i<=y;++i)
{
k[m].a=i;
k[m++].b=reverse(i);
}
/*
for(i=0;i<m;++i)
{
printf("%d ",k[i].b);
}
printf("\n");*/
sort(k,k+m,cmp);
for(i=0;i<m;++i)
{
if(i==m-1)
printf("%d\n",k[i].a);
else
printf("%d ",k[i].a);
}
}
}