设有n个正整数 (n<=20), 将它们连接成一排, 组成一个最大的多位整数.
例如: n=3时, 3个整数13, 312, 343连接成的最大整数为: 34331213
又如: n=4时, 4个整数7,13,4,246连接成的最大整数为: 7424613
输入格式:
n n个数
输出格式:
连接成的多位数
输入样例#1:
3
13 312 343
4
7 13 4 246
输出样例#1:
34331213
7424613
stl大法好啊,,总感觉这题在哪儿做过
注意一下条件不要写a>b不然
3
9 90 9这组数据过不了!!
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 }