Files
python/TangDou/LuoGuBook/P1012.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

21 lines
526 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const int N = 30;
string a[N];
bool cmp(const string &a, const string &b) {
//自定义排序函数这一步非常巧妙假设a=321b=32a+b=32132b+a=32321
// 这样下面sort排下来就是32>321避免出现32132>32321的情况
return a + b > b + a;
}
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + 1 + n, cmp);
for (int i = 1; i <= n; i++)cout << a[i];
return 0;
}