美文网首页
1038 Recover the Smallest Number

1038 Recover the Smallest Number

作者: 量化啦啦啦 | 来源:发表于2020-02-17 11:06 被阅读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;
    }
    

    相关文章

      网友评论

          本文标题:1038 Recover the Smallest Number

          本文链接:https://www.haomeiwen.com/subject/waqbfhtx.html