A1038
用一串数拼接成一个数,输出最小的。
思路:使用string和相关的函数。
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
const int maxn=;
string str[maxn];
bool cmp(string a,string b){
return a+b<b+a;
}
int main(){
int n;
cin>>n;
for(int i=;i<n;i++){
cin>>str[i];
}
sort(str,str+n,cmp);
string ans;
for(int i=;i<n;i++){
ans+=str[i];
}
while(ans.size()!=&&ans[]==''){
ans.erase(ans.begin());
}
if(ans.size()==) cout<<;
else cout<<ans;
return ;
}
A1038的更多相关文章
- A1038. Recover the Smallest Number
Given a collection of number segments, you are supposed to recover the smallest number from them. Fo ...
- A1038 Recover the Smallest Number (30 分)
一.技术总结 此问题是贪心类问题,给出可能有前导零的数字串,将他们按照某个顺序拼接,使生成的数最小. 解决方案,就是使用cmp函数,因为两两字符串进行拼接,进行排序从小到大. 拼接过后会有0可能出现在 ...
- PAT甲级——A1038 Recover the Smallest Number
Given a collection of number segments, you are supposed to recover the smallest number from them. Fo ...
- 1038 Recover the Smallest Number (30 分)
1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to r ...
- 1.21 贪心入门上午PAT例题题解
1.B1023 #include<cstdio> int a[10]; int main() { for(int i=0;i<=9;i++) { scanf("%d&quo ...
- PAT_A1038#Recover the Smallest Number
Source: PAT A1038 Recover the Smallest Number (30 分) Description: Given a collection of number segme ...
- PAT甲级题解分类byZlc
专题一 字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...
随机推荐
- [翻译] IQAudioRecorderController
IQAudioRecorderController IQAudioRecorderController is a drop-in universal library allows to record ...
- December 18th 2016 Week 52nd Sunday
May your love soar on the wings of a dove in flight. 愿你的爱乘着飞翔中的白鸽,展翅高飞. May my life soar on the wing ...
- Android 6.0动态权限申请教程
转载请标明出处: http://www.cnblogs.com/why168888/p/6580396.html 本文出自:[Edwin博客园] PermissionManage 介绍 如果设备运行的 ...
- chrome浏览器Network面板请求Timing分析
Timing显示资源在整个请求生命周期过程中各部分话费的时间. Queueing 排队的时间花费.可能由于该请求被渲染引擎认为是优先级比较低的资源(图片).服务器不可用.超过浏览器并发请求的最大连接数 ...
- centos虚拟机安装,配置静态ip可以访问网络
centos安装过程中需要注意几个问题 1.选择安装的软件 默认选择的是mininal,应该选择GNEME Desktop 安装的过程中可以设置network 配置linux网络命令 具体配置 退出键 ...
- [枫叶学院] Unity3d高级开发教程 工具集(一) 哈希列表——强大的自己定义数据集
在日常开发中.数据集合是我们不可缺少的重要工具之中的一个.在C#中,.Net Framework也为我们提供了种类繁多,功能多样的数据集工具.在此,我基于List<T> 和 HashTab ...
- Mysql分区表及自动创建分区Partition
Range分区表建表语句如下,其中分区键必须和id构成主键和唯一键 CREATE TABLE `test1` ( `id` char(32) COLLATE utf8mb4_unicode_ci NO ...
- 2018-2019-2 网络对抗技术 20165322 Exp4 恶意代码分析
2018-2019-2 网络对抗技术 20165322 Exp4 恶意代码分析 目录 实验内容与步骤 系统运行监控 恶意软件分析 实验过程中遇到的问题 基础问题回答 实验总结与体会 实验内容与步骤 系 ...
- 1412. [ZJOI2009]狼和羊的故事【最小割】
Description “狼爱上羊啊爱的疯狂,谁让他们真爱了一场:狼爱上羊啊并不荒唐,他们说有爱就有方向......” Orez听到这首歌,心想:狼和羊如此和谐,为什么不尝试羊狼合养呢?说干就干! O ...
- showDoc项目文档管理工具
1:下载showdoc代码文件 https://github.com/star7th/showdoc https://www.showdoc.cc/help?page_id=14 官方帮助文档 2:安 ...