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

返回目录

题目链接
在这里插入图片描述

#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();
    }
}

猜你喜欢

转载自blog.csdn.net/a1920993165/article/details/129381772
今日推荐