当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

AFMG SysTune1.3.7使用图解

如何运用3DGIS技术整合智慧社区综合管理解决方案

从头开始实现YOLOV3

Line generation 005

Learn about the sequential storage structure of binary tree - heap

Qt常见问题

batch_size of deep learning foundation

其他重要协议(DNS,ICMP,NAT,交换机)

Anatomy of Unreal Playback System (Part 1)

OpenPCDet environment configuration of 3 d object detection and demo test
随机推荐
Arduino框架下ESP32重启原因串口信息输出示例
违约金过高”的认定依据
ADSP21489数据手册表摘要
PyQt5_pyqtgraph mouse draws straight lines on line charts
【C语言程序】求直角三角形边长
数学建模学习(76):多目标线性规划模型(理想法、线性加权法、最大最小法),模型敏感性分析
300M级mysql数据库跨版本迁移流程
batch_size of deep learning foundation
关于地图GIS开发事项的一次实践整理(上)
列表总结
学内核之四:关于内核与硬件的衔接
日本痴汉打赏女主播1.5亿,结果。。。
CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) C题
线代005
立方体卫星Light-1
应用pca和K-means实现用户对物品类别的喜好细分划分
Use the advanced timer of GD32F207 to generate hidden bugs in PWM waves
论文速读:Homography Loss for Monocular 3D Object Detection
P1192 台阶问题
ScholarOne Manuscripts submits journal LaTeX file and cannot convert PDF successfully!