当前位置:网站首页>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;
}
边栏推荐
- Visual SLAM Lecture Fourteen - Lecture 13 Practice: Designing a SLAM system (the most detailed code debugging and running steps)
- 关于地图GIS的一次实践整理(下) Redis的GIS实践
- Minecraft 1.18.1、1.18.2模组开发 23.3D动画盔甲制作
- Qt FAQ
- “数字化重构系统,搞定 CEO 是第一步”
- 力扣练习——37 复原IP地址
- 如何运用3DGIS技术整合智慧社区综合管理解决方案
- 爬虫_爬取wasde月度供需平衡表(实例)
- DOM系列之 click 延时解决方案
- PDF文件转换格式
猜你喜欢
随机推荐
PyQt5_pyqtgraph鼠标在折线图上画直线
AFMG SysTune1.3.7使用图解
你要的在这里,自己维护的石墨文档
Crawler_crawl wasde monthly supply and demand balance table (example)
【STM32】ADC采集光敏数据(不看库函数手册进行配置)
Deep blue college - handwritten VIO operations - the first chapter
C语言可以应用在哪些领域?
Live | 7.30 ApacheCon Asia 2022 IOT/IIOT topic, IoTDB PMC Qiao Jialin as the producer
【七夕】是时候展现专属于程序员的“浪漫”了
ADSP21489仿真:Failed to set breakpoint: Can‘t set breakpoints in the current state: Running
斐波那契数列
什么是接触电流怎么测?
学内核之五:问题一,关于上下文切换
力扣练习——45 二叉树的锯齿形层次遍历
力扣练习——40 区间和的个数
CaDDN code debugging
Minecraft 1.18.1、1.18.2模组开发 23.3D动画盔甲制作
DOM系列之 click 延时解决方案
Visual SLAM Lecture Fourteen - Lecture 13 Practice: Designing a SLAM system (the most detailed code debugging and running steps)
单调队列模板 滑动窗口








