题解 | #大整数排序#

大整数排序

https://www.nowcoder.com/practice/b744af632ac4499aa485d7bb048bb0aa

#include<iostream>
#include<queue>
#include<string>
using namespace std;


struct str{
    string s;
    int len;
    str(string str,int l):s(str),len(l){}
    bool operator<(const str& st)const{
        if(len==st.len)
            return s>st.s;
        return len>st.len;
    }
};
int main(){
    int n;
    while(cin>>n){
        string s;
        priority_queue<str> pq;
        while(n--){
            cin>>s;
            pq.push(str(s,s.size()));
        }
        while(pq.size()){
            cout<<pq.top().s<<endl;
            pq.pop();
        }
    }
    return 0;
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务