luogu part 1.3 spelling (string based)

P1012 [NOIP1998 Improving Group] Spelling

Description Title
has positive integer nn A_1 \ DOTS a_na
. 1 ... A n- a maximum integer, which are coupled in a row, end to end adjacent digital form.




Input format
There is an integer in the first line, which represents the number of digits nn.

The second line has nn integers, given nn represents an integer a_ia
I .

Output format
A positive integer, representing the largest integer

Input and output sample
input #1 copy
3
13 312 343
output #1 copy
34331213
input #2 copy
4
7 13 4 246
output #2 copy
7424613
Note/Hint
For all test points, ensure 1 \leq n \leq 201≤n ≤20,1 \ Leq a_i \ ^ Leq 10 91≤a
I ≦ 10 . 9 .



#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
int n;
bool cmp(string a,string b){
    
    //避免321大于32 
	return a+b>b+a;//32132 32321
}
int main(){
    
    
	string s[25];
	
	cin>>n;
	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];
	return 0;
	
}

Guess you like

Origin blog.csdn.net/Minelois/article/details/113763825