0
点赞
收藏
分享

微信扫一扫

ECNU3039. 按整数最高位的值排序


ECNU3039. 按整数最高位的值排序_c++

#include <bits/stdc++.h>
using namespace std;

struct elex{
long long num;
long long hp;
};
bool cmp(elex x1,elex x2){
if(x1.hp==x2.hp)return x1.num<x2.num;
return x1.hp>x2.hp;
}

int main() {
int T;
cin>>T;
vector<elex> numl;
for(int tt=0;tt<T;tt++){
int N;
scanf("%d",&N);
long long x;
while(N--){
scanf("%lld",&x);
elex te;
te.num=x;
te.hp=abs(x);
while(1){
if(te.hp>=10){
te.hp=te.hp/10;
}else{
break;
}
}
numl.push_back(te);
}
sort(numl.begin(),numl.end(),cmp);
printf("case #%d:\n",tt);
for(auto it=numl.begin();it!=numl.end();it++){
printf("%lld",it->num);
if(it!=numl.end()-1)printf(" ");
else printf("\n");
}
numl.clear();
}
}


举报

相关推荐

0 条评论