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& ...
随机推荐
- Java 8 Date-Time API概览
更新时间:2018-04-19 根据网上资料整理 java 8增加了新的Date-Time API (JSR 310),增强对日期与时间的处理.它在很大程度上受到Joda-Time的影响.之前写过一篇 ...
- [翻译] VLDContextSheet
VLDContextSheet 效果: A clone of the Pinterest iOS app context menu. 复制了Pinterest应用的菜单效果. Example Usag ...
- [翻译] CHAnimation
CHAnimation https://github.com/cyndibaby905/CHAnimation How it looks CHAnimation is a project used t ...
- rabbitmq集群步骤
这里选用三台主机,主机名分别是hidden1, hidden2, hidden3 主机名一定要修改成不一样的,要不然加入集群的时候会加入不成功 修改完主机名后,在/etc/hosts文件中加入对应的解 ...
- Android 通过触摸动态地在屏幕上画矩形
需求概述: 在屏幕上用手指画出一个区域,返回所圈的区域坐标. 技术实现: 自定义View,设置画笔及对应参数,在onTouchEvent()回调函数里,对触摸事件进行判断.画出矩形图形. 代码: 自定 ...
- Undirected Graphs
无向图 Introduction 图是由边连接的点的集合,有着广泛的应用空间. 一些图的术语,点,边,路径,环(圈),连通分量(子图). 简单路径不重复经过点,简单环不含有重复点和边,简单图不含自环和 ...
- [T-ARA][20090729]
歌词来源:http://music.163.com/#/song?id=484058959 在基本发音规则之上,考虑到了音变的某些情况,最后结合听力搞定的一版歌词发音(只要学完养乐多老师的教程应该读起 ...
- PhoneGap API 之事件处理_双击返回键退出程序
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 【[POI2010]ANT-Antisymmetry】
开始复习字符串了 第一步肯定得是\(hash\) 首先理性分析一波不可能出现长度为奇数的反回文串,对称轴位置取反之后肯定和原来不相等了 我们可以枚举所有回文串的对称中心,之后我们发现这个样子是具有单调 ...
- 24、springboot与缓存(2)
具体看上文!!! @Service public class EmpService { @Autowired EmployeeMapper employeeMapper; @Cacheable(cac ...