#include <stdio.h>
#include <algorithm>
using namespace std;
struct st{
int a,b;//a为火星数,b为地球数
}c[100];
int f(int x)//把火星数转换为地球数
{
int y=0,z;
while (x!=0)
{
z=x%10;
if(z==0) z=0;
else if (z==8) z=1;
else if (z==1) z=2;
else if (z==5) z=3;
else if (z==2) z=4;
else if (z==3) z=5;
else if (z==9) z=6;
else if (z==4) z=7;
else if (z==7) z=8;
else if (z==6) z=9;
y=y*10+z;
x=x/10;
}
while (y!=0)
{
z=y%10;
x=x*10+z;
y=y/10;
}
return x;
}
cmp(st x,st y)//排序
{
return x.b<y.b;
}
int main()
{
int n,n1,i,j;
scanf("%d",&n);
for (i=1;i<=n;i++)
{
scanf("%d",&n1);
for (j=1;j<=n1;j++)
{
scanf("%d",&c[j].a);
c[j].b=f(c[j].a);
}
sort(c+1,c+1+n1,cmp);
for (j=1;j<=n1;j++)
printf("%d ",c[j].a);
printf("\n");
}
return 0;
}
你的cmp(st x,st y) 没有返回值啊。
肯定编译错误。
你 cmp(st x,st y)没有声明返回值类型
改成
bool cmp(st x,st y)//排序
如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!
题目描述
哈哈,大家对地球上的排序规则都比较清楚了吧!可是火星上的规则跟地球上的不一样。地球上的十个数字的顺序是{0,1,2,3,4,5,6,7,8,9},火星上的却是{0,8,1,5,2,3,9,4,7,6}。好在火星上基本数字也是十个,也是十进制,因此,很容易推得9<80<88<81<… 请根据火星上的规则对火星数进行从小到大的排序。
输入
第一行为Case,表明接下来有Case组输入数据,每组数据的开头为N,表明该行接下来有N个数,然后是N个火星数中间以一个空格隔开
输出
每组输出只占一行,为N个经过火星排序的数