文章

43

粉丝

24

获赞

293

访问

6.6k

头像
大整数排序 题解:马+7超绝简单易懂思路无敌坤坤打篮球版
P1412 华中科技大学机试题
发布于2025年2月9日 12:09
阅读数 247

#include <bits/stdc++.h>
using namespace std;
//思路:利用string的排序,若字符串长度相同,则根据ASCII排序,
//        否则,长的元素更大 
    bool cmp(string a,string b){
        if(a.size()==b.size())
            return a<b;
        return a.size()<b.size();
    }
int main(){
    int n;
    while(cin>>n){
        string str[101];
        int i;
        for(i=0;i<n;i++){
            cin>>str[i];
        }
        sort(str,str+n,cmp);
        for(i=0;i<n;i++){
            cout<<str[i] <<endl;
&...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发