当前位置:网站首页>P1012 [NOIP1998 提高组] 拼数
P1012 [NOIP1998 提高组] 拼数
2022-08-02 04:03: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
思路
主要是对字符串的处理,难点在于不知道输入数字的位数,没办法通过单一的比较数字大小来排序,所以想到了可以通过字符串来比较,通过
bool cmp(string a, string b) {
return a + b > b + a;
}
来判断先后
具体代码
#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;
}
边栏推荐
猜你喜欢

数据可视化之百变柱状图

深蓝学院-视觉SLAM十四讲-第七章作业

如何解决QByteArray添加quint16双字节时错误?

The most authoritative information query steps for SCI journals!

投资组合分析:portfolio_analysis.Tangenvy_portfolio(切点组合)

Visual SLAM Lecture Fourteen - Lecture 13 Practice: Designing a SLAM system (the most detailed code debugging and running steps)

Platts Analysis-MATLAB Toolbox Function

SCI writing strategy - with common English writing sentence patterns

internship:数据库表和建立的实体类及对应的枚举类之间的联系示例

如何让固定点的监控设备在EasyCVR平台GIS电子地图上显示地理位置?
随机推荐
吴恩达机器学习系列课程笔记——第十三章:聚类(Clustering)
Research Notes (8) Deep Learning and Its Application in WiFi Human Perception (Part 1)
【STM32】 ADC模数转换
CaDDN code debugging
列表总结
吴恩达机器学习系列课程笔记——第八章:神经网络:表述(Neural Networks: Representation)
C语言特殊运算符
lvm扩容(实战无废话)
ClickHouse的客户端命令行参数
Pycharm platform import scikit-learn
CaDDN paper reading of monocular 3D target detection
复制延迟案例(3)-单调读
(一)代码输出题 —— reverse
深蓝学院-手写VIO作业-第一章
Research Notes (8) Deep Learning and Its Application in WiFi Human Perception (Part 2)
吴恩达机器学习系列课程笔记——第六章:逻辑回归(Logistic Regression)
Deep blue college - handwritten VIO operations - the first chapter
深蓝学院-手写VIO作业-第二章
falco 【1】入门
AFMG SysTune1.3.7使用图解