计蒜客 - T2144 拼数
题解:把所有数字看成字符串,但是难道直接降序排就结束了嘛,不是的,我们来看一个反例:31 312 虽然312>31但是明显31312 > 31231,所以我们不能简单的排序,我们需要比较两个字符串x,y 如果x+y>y+x就将x排到前面,否则将y排到前面
#include <bits/stdc++.h>
#define Zeoy std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define endl '\n'
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-9;
const int N = 2e5 + 10;
vector<string> a;
int cmp(string x, string y)
{
return x + y > y + x;
}
int main(void)
{
Zeoy;
int t = 1;
// cin >> t;
while (t--)
{
int n;
cin >> n;
for (int i = 1; i <= n; ++i)
{
string s;
cin >> s;
a.push_back(s);
}
sort(all(a), cmp);
for (auto i : a)
cout << i;
cout << endl;
}
return 0;
}
标签:std,const,拼数,int,计蒜客,T2144,define
From: https://www.cnblogs.com/Zeoy-kkk/p/17031807.html