Maximum P1107 integer and P1107 integer
Description
There are n positive integers (n <= 20) connected into a row to form a maximum of multiple integers.
For example, when n = 3, the maximum integer connected by 3 integers 13,312,343 is 34331213.
For example, when n = 4, the maximum integer of the 4 integers 7, 13, and 4,246 is 7424613.
Input/Output Format
Input Format:
Nn count
Output Format:
Multiple Digits connected
Input and Output sample
Input example #1:
313 312 34347 13 4 246
Output sample #1:
343312137424613
Stl is good. I always feel where I have done this.
Note that the condition is not a> B. Otherwise
3
9 90 9 this group of data cannot pass !!
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 using namespace std; 7 const int MAXN=21; 8 int read(int & n) 9 {10 char c='.';int x=0,flag=0;11 while(c<'0'||c>'9')12 {13 c=getchar();14 if(c=='-')flag=1;15 }16 while(c>='0'&&c<='9')17 {18 x=x*10+(c-48);19 c=getchar();20 }21 if(flag==1)n=-x;22 else n=x;23 }24 string s[21];25 int comp(const string & a,const string & b)26 {27 return a+b>b+a;28 }29 int main()30 {31 int n;32 while(cin>>n)33 {34 for(int i=1;i<=n;i++)35 cin>>s[i];36 sort(s+1,s+n+1,comp);37 for(int i=1;i<=n;i++)38 cout<<s[i]; 39 }40 41 return 0;42 }