将正整数链接成一行,相邻数字首尾相接,组成一个最大的整数

设有 n个正整数 a1 a2 ... an​,将它们连接成一行,相邻数字首尾相接,组成一个最大的整数。

例如:13、312、343 可以组合成为的最大数为 34331213 。

输入数据共两行,第一行有一个整数,表示数字个数 n。第二行有 n 个整数,表示给出的 n 个整数 a1 到 an。

输入:
3
13 312 343
输出:
34331213

输入:
4
7 13 4 246
输出:
7424613


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    cin >> n;
    string num;
    vector<string> v;
    while ((n--) > 0)
    {
        cin >> num;
        v.push_back(num);
    }
    sort(v.begin(), v.end(), [](const string& s1, const string& s2) -> bool {
        return (s1 + s2).compare(s2 + s1) > 0;
        });
    for_each(v.begin(), v.end(), [](string s) { cout << s; });
    cout << endl;
    system("pause");
    return 0;
}