首页 > 编程语言 >nyoj 540 第五届河南省程序设计大赛A

nyoj 540 第五届河南省程序设计大赛A

时间:2022-11-21 21:03:58浏览次数:67  
标签:dian node return shu int nyoj xx 540 程序设计



奇怪的排序



1000 ms  |  内存限制: 65535



1


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

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


第一行: N表示有多少组测试数据. (2<=N<=5 )

接下来有N行,每一行有两个正整数A B表示待排序元素的区间范围. (1<=A<=B<=200000 B-A<=50)


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

2 8 15 22 39




样例输出

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




来源 ​​第五届河南省程序设计大赛​

上传者 ​​ACM_李如兵​





只会两个难度为1的题-.-战斗力为1的渣渣。。。。。。。。。

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int ko(int xx)
{
int kp=0;
while (xx)
{
kp=kp*10+xx%10;
xx/=10;
}
return kp;
}
struct node
{
int shu;
int dao;
}dian[200100];
bool qiu(node xx,node yy)
{
return xx.dao<yy.dao;
}
bool hui(node xx,node yy)
{
return xx.shu<yy.shu;
}
int main()
{
int t,a,b,i;scanf("%d",&t);
for (i=0;i<=200001;i++)
{
dian[i].shu=i;
dian[i].dao=ko(i);
}
while (t--)
{
scanf("%d%d",&a,&b);
sort(dian+a,dian+b+1,qiu);
for (i=a;i<b;i++)
printf("%d ",dian[i].shu);
printf("%d\n",dian[i].shu);
sort(dian+a,dian+b+1,hui);
}
return 0;
}



标签:dian,node,return,shu,int,nyoj,xx,540,程序设计
From: https://blog.51cto.com/u_15886902/5875288

相关文章