当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
A Practical Arrangement of Map GIS Development Matters (Part 1)
JDBC再回顾
Camtasia 2022简体中文版屏幕录像和视频编辑软件
Arduino框架下STM32F1/F4系列HID模式程序烧录教程
ADSP21489仿真:Failed to set breakpoint: Can‘t set breakpoints in the current state: Running
Deep Blue Academy - Handwritten VIO Homework - Chapter 2
7亿听众背后的在线音频掘金故事
2022-08-01:以下go语言代码输出什么?A:panic;B:5;C:6;D:编译错误。 package main import ( “fmt“ ) func main() {
Arduino框架下 ESP32看门狗使用示例
学内核之五:问题一,关于上下文切换
随机推荐
什么是接触电流怎么测?
Qt FAQ
数据可视化之百变柱状图
翻转(DAY 97)
面试官:大量请求 Redis 不存在的数据,从而打倒数据库,有什么方案?
【数字IC手撕代码】Verilog固定优先级仲裁器|题目|原理|设计|仿真
Minecraft 1.18.1, 1.18.2 module development 23.3D animation armor production
Platts Analysis-MATLAB Toolbox Function
C语言可以应用在哪些领域?
Batch normalization (BN) based on deep learning
【STM32】 ADC模数转换
【C语言程序】求直角三角形边长
力扣 剑指 Offer 56 - I. 数组中数字出现的次数
Arduino框架下ESP32重启原因串口信息输出示例
关于地图GIS的一次实践整理(下) Redis的GIS实践
力扣练习——37 复原IP地址
P1012 [NOIP1998 提高组] 拼数
Scala基础【常用方法补充、模式匹配】
开放原子开源峰会落幕,百度超级链牵头成立XuperCore开源工作组
gergovia's deal tijie