当前位置:网站首页>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;
}
边栏推荐
- 康威定律对于系统架构很重要吗?
- 安装部署 Kubernetes 仪表板(Dashboard)
- A practice arrangement about map GIS (below) GIS practice of Redis
- WordPress是什么?我也想用 WordPress~
- batch_size of deep learning foundation
- 开放原子开源峰会落幕,百度超级链牵头成立XuperCore开源工作组
- [Errno 13] Permission denied:’/usr/local/share/jupyter’
- PyQt5_pyqtgraph mouse draws straight lines on line charts
- 力扣练习——39 正方形数组的数目
- How to decrypt worksheet protection in Excel
猜你喜欢
线代005
轮询和长轮询的区别
Batch normalization (BN) based on deep learning
Deep blue college - handwritten VIO operations - the first chapter
How to save a section of pages in a PDF as a new PDF file
Camtasia 2022简体中文版屏幕录像和视频编辑软件
【云原生】什么是CI/CD? | CI/CD 带来的好处
关于地图GIS的一次实践整理(下) Redis的GIS实践
如果有些字段不想进行序列化怎么办?
2022 Huawei Software Elite Challenge (Preliminary) - Summary
随机推荐
力扣练习——45 二叉树的锯齿形层次遍历
系统层面知识连接收藏
力扣练习——41 对称二叉树
Deep blue college - handwritten VIO operations - the first chapter
Minecraft 1.18.1, 1.18.2 module development 23.3D animation armor production
redis基础入门
alibaba数据同步组件canal的实践整理
什么是接触电流怎么测?
浅学一下二叉树的顺序存储结构——堆
康威定律对于系统架构很重要吗?
A practice arrangement about map GIS (below) GIS practice of Redis
8月1日“海豹数藏”将全网首发民族英雄林则徐《四行行书》数字藏品!
如果有些字段不想进行序列化怎么办?
7亿听众背后的在线音频掘金故事
违约金过高”的认定依据
Go 语言是如何实现切片扩容的?【slice】
关于地图GIS开发事项的一次实践整理(上)
internship:数据库表和建立的实体类及对应的枚举类之间的联系示例
洛谷P2670扫雷游戏
爬虫_爬取wasde月度供需平衡表(实例)