P1012 拼数

题目描述

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

例如:n=3n=3时,33个整数1313,312312,343343联接成的最大整数为:3433121334331213

又如:n=4n=4时,44个整数77,1313,44,246246联接成的最大整数为:74246137424613

输入格式

第一行,一个正整数nn。

第二行,nn个正整数。

输出格式

一个正整数,表示最大的整数

输入输出样例

输入 #1

3
13 312 343

输出 #1

34331213
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <climits>
#include <stdio.h>
#include <iomanip>
#include <math.h>   
#include <list>
#include <queue>
#include <tuple> 
#include <stack>
#include <string.h>
using namespace std;


bool mycmp(const string& A, const string& B)
{
	string tmp1 = A + B;
	string tmp2 = B + A;
	if(tmp1 > tmp2)
		return true;
	return false; 
}

int main(void)
{
	int n;
	cin >> n;
	vector<string> nums(n);
	for(int i = 0; i < n; i++)
	{
		cin >> nums[i];
	}
	sort(nums.begin(), nums.end(), mycmp);
	string ret;
	for(auto& tmp : nums)
	{
		ret += tmp;
	}
	cout << ret << endl;
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值