1 条题解

  • 1
    @ 2026-8-4 15:49:16

    用sort()排序的方法

    #include <iostream>
    #include <string>
    #include <vector>
    #include <algorithm>
    using namespace std;
    
    int main() {
        int n;
        cin >> n;
        vector<string> a(n);
        for(int i = 0; i < n; i++) {
            cin >> a[i];
        }
    
        sort(a.begin(), a.end(), [](const string &x, const string &y) {
            return x + y > y + x;
        });
    
        string ans;
        for (auto &s : a) ans += s;
    
        if (ans[0] == '0') cout << "0";
        else cout << ans;
    
        return 0;
    }
    
    
    • 1

    信息

    ID
    5134
    时间
    1000ms
    内存
    128MiB
    难度
    7
    标签
    递交数
    5
    已通过
    4
    上传者