P1012拼数

要灵活运用sort函数:

利用bmp函数对其进行自定义规则的排序

```cpp
#include <bits/stdc++.h>

using namespace std;

int n;
string a[30];

bool bmp(const string& a, const string& b)
{
    return a + b > b + a;
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(0);
    
    cin >> n;
    for (int i = 0;i < n;i ++)
        cin >> a[i];

    sort(a, a+n, bmp);
    
    for (int i = 0;i < n;i ++)
        cout << a[i];

    return 0;
}
posted @ 2024-11-25 15:26  windfallll  阅读(16)  评论(0)    收藏  举报