codevs——T1860 最大数||洛谷——P1107 最大整数

||

  设有n个正整数(n≤20),将它们联接成一排,组成一个最大的多位整数。

输入描述 Input Description

  第一行一个正整数n。

  第二行n个正整数,空格隔开。

 

输出描述 Output Description

  连接成的多位数。

样例输入 Sample Input

Sample 1:

3

13 312 343

 

Sample 2:

4

7 13 4 246

 

样例输出 Sample Output

Sample 1:

34331213

 

Sample 2:

7424613

 

数据范围及提示 Data Size & Hint

n≤20

 

 1 #include <algorithm>
 2 #include <iostream>
 3 #include <cstring>
 4 
 5 using namespace std;
 6 
 7 int n;
 8 string s[21];
 9 
10 bool cmp(string a,string b)
11 {
12     return a+b>b+a;
13 }
14 
15 int main()
16 {
17     cin>>n;
18     for(int i=1;i<=n;i++)
19         cin>>s[i];
20     sort(s+1,s+n+1,cmp);
21     for(int i=1;i<=n;i++)
22         cout<<s[i];
23     return 0;
24 }

 

posted @ 2017-02-18 15:37  Aptal丶  阅读(180)  评论(0编辑  收藏  举报