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

The line chart with square PyQt5_pyqtgraph mouse

DOM系列之 click 延时解决方案

ADSP21489仿真:Failed to set breakpoint: Can‘t set breakpoints in the current state: Running

使用pycharm debug 深度学习代码

ROS visualization of 3D target detection

使用 Fastai 构建食物图像分类器

学内核之四:关于内核与硬件的衔接

Qt常见问题

力扣 215. 数组中的第K个最大元素

投资组合分析:portfolio_analysis.Tangenvy_portfolio(切点组合)
随机推荐
力扣练习——48 找到小镇的法官
【STM32】 ADC模数转换
Go 语言是如何实现切片扩容的?【slice】
CaDDN code debugging
论文速读:Homography Loss for Monocular 3D Object Detection
7亿听众背后的在线音频掘金故事
力扣练习——单词搜索
Liquidated damages are too high"
如何运用3DGIS技术整合智慧社区综合管理解决方案
立方体卫星Light-1
Arduino框架下 ESP32看门狗使用示例
力扣练习——40 区间和的个数
区间和 离散化
Use the advanced timer of GD32F207 to generate hidden bugs in PWM waves
How to decrypt worksheet protection in Excel
Batch normalization (BN) based on deep learning
力扣练习——43 路径总和
洛谷P2437蜜蜂路线
ffmpeg基本命令
LeetCode 23: 合并K个升序链表