当前位置:网站首页>P1012 [NOIP1998 Improve Group] Spelling
P1012 [NOIP1998 Improve Group] Spelling
2022-08-02 05:45:00 【zjsru_Beginner】
P1012 [NOIP1998 提高组] 拼数
题目描述
设有 n个正整数a1…an;,将它们联接成一排,相邻数字首尾相接,组成一个最大的整数.
输入格式
第一行有一个整数,表示数字个数 n.
第二行有 n 个整数,表示给出的 n 个整数 a1…an;
输出格式
一个正整数,表示最大的整数
输入输出样例:
输入1
3
13 312 343
输出1
34331213
输入2
4
7 13 4 246
输出2
7424613
思路
Mainly dealing with strings,The difficulty is not knowing the number of digits in the input number,There is no way to sort by a single comparison of number size,So I thought of comparing by strings,通过
bool cmp(string a, string b) {
return a + b > b + a;
}
to judge
具体代码
#include <iostream>
#include<string>
#include <algorithm>
#include <cstdlib>
#define maxn 25
using namespace std;
bool cmp(string a, string b) {
return a + b > b + a;
}
int main()
{
int n;
string a[maxn];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n, cmp);
for (int i = 0; i < n; i++) {
cout << a[i];
}
cout << endl;
return 0;
}
边栏推荐
猜你喜欢
随机推荐
P1012 [NOIP1998 提高组] 拼数
一次跳出最外层循环
ScholarOne Manuscripts submits journal LaTeX file and cannot convert PDF successfully!
Line generation 005
Camtasia 2022简体中文版屏幕录像和视频编辑软件
抓住那头牛(DAY 96)
Luogu P2437 Bee Route
gergovia's deal tijie
其他重要协议(DNS,ICMP,NAT,交换机)
批量--10---根据set数拆分文件
nr部分计算
alibaba数据同步组件canal的实践整理
26. 如何判断一个对象是否存活?(或者GC对象的判定方法)?
ADSP21489工程中LDF文件配置详解
C# Thread IsBackground作用
单调队列模板 滑动窗口
深度剖析-class的几个对象(utlis,component)-瀑布流-懒加载(概念,作用,原理,实现步骤)
讯飞AIUI智能机器人5-----让器理解你(语音技术综合应用)
PyQt5_pyqtgraph鼠标在折线图上画方形
论文速读:Homography Loss for Monocular 3D Object Detection









