文章

35

粉丝

0

获赞

144

访问

7.3k

头像
vector秒了,简简单单
P1412 华中科技大学机试题
发布于2025年3月13日 11:22
阅读数 198

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

bool cmp(string a, string b){
    if (a.length() != b.length()) {
        return a.length() < b.length();  // 长度小的字符串对应的数字较小
    }
    return a < b;  // 长度相等时,逐字符比较
}

int main(){
    int n;
    while(cin >> n){
        vector<string> v(n); 
        for (int i = 0; i < n; i++){
            cin >> v[i];
        }
        sort(v.begin(), v.end(), cmp);  
        for(const string& c : v){  
            cout << c << endl;
        }
    }
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发