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

Live | 7.30 ApacheCon Asia 2022 IOT/IIOT topic, IoTDB PMC Qiao Jialin as the producer

康威定律对于系统架构很重要吗?

从头开始实现YOLOV3

学内核之五:问题一,关于上下文切换

被大厂强制毕业,两个月空窗期死背八股文,幸好上岸,不然房贷都还不上了

【C语言程序】求直角三角形边长

Deep blue college - handwritten VIO operations - the first chapter

How to save a section of pages in a PDF as a new PDF file

Arduino框架下ESP32重启原因串口信息输出示例

论文速读:Homography Loss for Monocular 3D Object Detection
随机推荐
力扣练习——43 路径总和
MySQL存储函数详解
数学建模学习(76):多目标线性规划模型(理想法、线性加权法、最大最小法),模型敏感性分析
Go 语言是如何实现切片扩容的?【slice】
Deep blue college - handwritten VIO operations - the first chapter
Live | 7.30 ApacheCon Asia 2022 IOT/IIOT topic, IoTDB PMC Qiao Jialin as the producer
力扣练习——37 复原IP地址
EasyCVR视频广场切换通道,视频播放协议异常的问题修复
浅学一下二叉树的顺序存储结构——堆
Learn about the sequential storage structure of binary tree - heap
P1192 台阶问题
Minecraft 1.18.1, 1.18.2 module development 23.3D animation armor production
Digicert EV证书签名后出现“证书对于请求用法无效”的解决方案
HyperLynx中层叠设计实例
你要的在这里,自己维护的石墨文档
Crawler_crawl wasde monthly supply and demand balance table (example)
七月阅读:《刘慈欣科幻短篇小说集Ⅰ》笔记
高等数学(第七版)同济大学 总习题三(前10题) 个人解答
Unreal回放系统剖析(上)
C语言特殊运算符