题意
给出若干数,要求输出他们拼接成的最大的数
思路
这题是出乎意料的简单()
主要是,不能直接根据字典序大小排列,而需要考虑的是两个串相加的大小,也就有了底下的cmp函数
代码
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define Endl "\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e7+5;
const int INF = 0x3f3f3f;
const int mod = 1e9 + 7;
const double pi = acos(-1);
inline ll read(){
ll x = 0, f = 1; char ch; ch = getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int N;
string s[maxn];
int cmp(string a,string b)
{
return a+b>b+a;
}
void solve() {
for(int i=0;i<N;i++)
cin>>s[i];
sort(s,s+N,cmp);
for(int i=0;i<N;i++)
cout<<s[i];
cout<<Endl;
return ;
}
int main() {
// for(int T = read(); T; T--)
while(N=read())
{
if(N!=0)
solve();
}
return 0;
}