1038 Recover the Smallest Number

2020-02-17  本文已影响0人  量化啦啦啦
image.png
/*
Sample Input:
5 32 321 3214 0229 87
Sample Output:
22932132143287
 */
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
bool cmp_segment(string a, string b) {
    return a + b < b + a;
}
string str[100010], ans;
int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> str[i];
    sort(str, str + N, cmp_segment);
    for (int i = 0; i < N; i++)
        ans += str[i];
    while (ans.length() != 0 && ans[0] == '0')
        ans.erase(ans.begin());
    if (ans.length() == 0)
        cout << 0;
    else
        cout << ans;
    return 0;
}
上一篇 下一篇

猜你喜欢

热点阅读