对于字符串排序,依据:
若a在b前面组成的字符串小于b在a前的字符串,则a在b前面,反之b在a前面
要注意
Do not output leading zeros.
例如 3 0 0 0
应只输出一个0
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
bool cmp(const string &a, const string &b){
return a + b < b + a;
}
int main(){
int n;
freopen("1.in", "r", stdin);
cin >> n;
string *str = new string[n];
int i;
for (i = 0; i < n; i++)
cin >> str[i];
sort(str, str + n, cmp);
bool flag = false;
for (i = 0; i < n; i++)
for (int j = 0; j < str[i].size(); j++){
if (!flag)
if (str[i][j] == '0')
continue;
else {
putchar(str[i][j]);
flag = true;
}
else putchar(str[i][j]);
}
if (!flag)
putchar('0');
cout << endl;
return 0;
}