1860 最大数

1860 最大数

链接:http://codevs.cn/problem/1860/

 

1998年NOIP全国联赛提高组

 时间限制: 1 s
 空间限制: 128000 KB
 
 
 
 
题目描述 Description

  设有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

题解:字符串连接后比较

#include<iostream>
#include<algorithm>
using namespace std;
string s[25];
bool cmp(string a,string b){
    return a+b>b+a;
}
int main(){
    int n;
    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];
    cout<<endl;
}
原文地址:https://www.cnblogs.com/EdSheeran/p/7454782.html