Luo Gu P1012 fight number (water title string

Title Description

With n- n-positive integer (n≤20) ( n- 2 0 ), which are coupled in a row to form a maximum number of integer.

For example: n-. 3 = n- = . 3, the . 3 3 integer 13 is . 1 3 312 . 3 . 1 2 and 343 . 3 . 4 coupling 3 to a maximum integer: 34,331,213 . 3 . 4 . 3 . 3 . 1 2 . 1 . 3

Another example: n-. 4 = n- = . 4, the . 4 4 integers . 7 7 13 is . 1 3 . 4 4 246 2 . 4 . 6 is coupled to a maximum integer: 7424613 . 7 . 4 2 . 4 . 6 . 1 . 3

 

Input #
  3
13 312 343
Output # 1
 
34331213


 
 
The last water x today (morning readily open string topics on smoothly finished ,,), entitled quite simply put together the biggest ,, obviously is based on a string lexicographically row, rather than the integer size (to ensure a high numbers as large as possible) ,, wa point is the last case, when a string is another string, need special sentenced moment, we can not just put lexicographically.
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int N = 1e3+7;
 5 string s[100];
 6 bool cmmp(string a,string b){
 7     int la = a.size(),lb = b.size();
 8     int l = min(la,lb);
 9     for(int i = 0;i < l;++i){
10         if(a[i]>b[i])return 1;//a在b前 1 
11         else if(a[i]<b[i])return 0;
12     }
13     if(la>lb){
14         if(a[lb]>a[0])return 1;
15         else return 0;
16     }
17     else if(la < lb){
18         if(b[la]>b[0])return 0;
19         else return 1; 
20     }
21     return 1;
22 }
23 int main(){
24     int n;string tp;
25     ios::sync_with_stdio(0);
26     cin>>n;
27     for(int i = 0;i < n;++i)cin>>s[i];
28     for(int i = 0;i < n;++i){
29         for(int j = i+1;j < n;++j){
30             if(cmmp(s[i],s[j])==0){
31                 tp = s[i];s[i] = s[j];s[j] = tp;
32             }
33         }
34     }
35     for(int i = 0;i < n;++i)cout<<s[i];cout<<endl;
36 }

 

Guess you like

Origin www.cnblogs.com/h404nofound/p/12179921.html