P1107 最大整数

P1107 最大整数

题目描述

设有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
原来可以这么做!!!
 1 #include<iostream>
 2 #include<string>
 3 #include<algorithm>
 4 using namespace std;
 5 string s[1010];
 6 int n;
 7 bool cmp(string a,string b)
 8 {
 9     return (a+b > b+a);
10 }
11 int main()
12 {
13     cin>>n;
14     for (int i=0; i<n; ++i)
15         cin>>s[i];
16     sort(s,s+n,cmp);
17     for (int i=0; i<n; ++i)
18         cout<<s[i];
19     return 0;
20 }
原文地址:https://www.cnblogs.com/mjtcn/p/7050313.html