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& ...
随机推荐
- 定义类/实例(Class)
# -*- coding: UTF-8 -*- class pp(): '''Description''' def __init__(self,name): #初始化函数 self.nam ...
- git使用教程2-更新github上代码
前面一篇已经实现首次上传代码到github了,迈出了装逼第一步,本篇继续讲如何把本地更新的代码同步更新到github上 一.clone代码 1.把大神的代码clone到本地,或者clone自己gith ...
- JavaScript的事件对象中的特殊属性和方法(鼠标,键盘)
鼠标操作导致的事件对象中的特殊属性和方法 鼠标事件是 Web 上面最常用的一类事件,毕竟鼠标还是最主要的定位设备.那么通过事件对象可以获取到鼠标按钮信息和屏幕坐标获取等 鼠标按钮 只有在主鼠标按钮被单 ...
- android中反射技术使用实例
在计算机科学领域.反射是指一类应用,它们能够自描写叙述和自控制.也就是说,这类应用通过採用某种机制来实现对自己行为的描写叙述(self-representation)和监測(examination), ...
- Spring4 SpringMVC Hibernate4 Freemaker 整合样例
更正改动(2014-05-30 13:47:22):有的IDE中web.xml会报这个错: cvc-complex-type.2.4.a: Invalid content was found star ...
- jQuery UI 实例 – 切换(Toggle)
toggle()函数用于为每个匹配元素的click事件绑定轮流的处理函数. toggle()是一个特殊的事件函数,用于为匹配元素的click事件绑定多个事件处理函数.每次触发click事件时,togg ...
- vector详讲(一)
<vector>头文件里带有两个类型参数的类模板,第一个参数是需要指定的数据类型,第二个是分配器(allocator)类型 template<class T, class Alloc ...
- [转]对象映射类AutoMapper的使用
由于原文太长了,此处就直接贴上原文的超链接,大家自行学习. codeproject中的一篇文章: AutoMapper
- fiddler常用功能一
fiddler备忘,好久不用,有些步骤忘记了 1.本机pc,目前ie和chrome都可以直接抓取,但是搜狗浏览器暂时抓不到 2.手机端抓包 (1)设置下代理:fiddler客户端查看下端口,然后在手机 ...
- 《Android应用测试与调试实战》读书笔记
一 本书概述 自动化测试篇:Android应用可以使用Java语言配合SDK,也可以使用HTML5技术,还可以用C/C++语言配合NDK技术编写,本书中涵盖了针对这三种技术编写的应用所采用的测试技术. ...