The Max Number


题目描述 
设有n个正整数(n ≤ 20),将它们联接成一排,组成一个最大的多位整数。
例如:n=3时,3个整数13312343联接成的最大整数为:34331213
又如:n=4时,4个整数7134246联接成的最大整数为:7424613

输入描述:
第一行,一个正整数n。
第二行,n个正整数。
输出描述:
一个正整数,表示最大的整数
示例1
输入

3
13 312 343
输出

34331213
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <set>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn=5e7+5;
const int Max = 0x3f3f3f;
const ll MOD = 1e9+7;
inline ll gcd(ll x, ll y){
    
    return y ? gcd(y, x % y) : x;}

bool cmp(std::string a, std::string b){
    
    
	return a+b>b+a;
}

vector<string> s;
int main(){
    
    
	IOS;
	int n;
	cin >> n;
	string dd;
	for (int i = 0; i < n; i++){
    
    
		cin >> dd;
		s.push_back(dd);
	}
	sort(s.begin(), s.end(), cmp);
	string kk ;
	for (int i = 0; i < s.size(); i++)
		kk+=s[i];
	cout << kk << endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_45465598/article/details/110789257
max