当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
使用 Fastai 构建食物图像分类器
Deep Learning Basics Overfitting, Underfitting Problems, and Regularization
A practice arrangement about map GIS (below) GIS practice of Redis
如何解决QByteArray添加quint16双字节时错误?
【每日一题】1374. 生成每种字符都是奇数个的字符串
Learn about the sequential storage structure of binary tree - heap
力扣练习——38 分割回文串
PDF文件转换格式
洛谷P2670扫雷游戏
EasyCVR视频广场切换通道,视频播放协议异常的问题修复
深度剖析-class的几个对象(utlis,component)-瀑布流-懒加载(概念,作用,原理,实现步骤)
力扣练习——33 原子的数量
批量--09---批量读文件入表
Minecraft 1.18.1, 1.18.2 module development 23.3D animation armor production
C - The Domino Effect(dfs+回溯)
【云原生】什么是CI/CD? | CI/CD 带来的好处
MySQL存储函数详解
什么是接触电流怎么测?
internship:数据库表和建立的实体类及对应的枚举类之间的联系示例
Scala basics [common method supplement, pattern matching]









