拼接最小正整数

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
bool cmp(const string& p1,const string& p2) {
    return p1 + p2 < p2 + p1;
}
int main(void) {
    int n;
    while (cin >> n) {
        vector<string> num(n);
        for (int i = 0; i < n;i++) {
            cin >> num[i];
        }
        sort(num.begin(), num.end(),cmp);
        string ans;
        for (int i = 0; i < num.size();i++) {
            ans += num[i];
        }
        cout << ans<<endl;
    }
    return 0;
}
posted @ 2021-11-18 20:23  Zupernova  阅读(15)  评论(0编辑  收藏  举报