用一串数拼接成一个数,输出最小的。

思路:使用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的更多相关文章

  1. A1038. Recover the Smallest Number

    Given a collection of number segments, you are supposed to recover the smallest number from them. Fo ...

  2. A1038 Recover the Smallest Number (30 分)

    一.技术总结 此问题是贪心类问题,给出可能有前导零的数字串,将他们按照某个顺序拼接,使生成的数最小. 解决方案,就是使用cmp函数,因为两两字符串进行拼接,进行排序从小到大. 拼接过后会有0可能出现在 ...

  3. PAT甲级——A1038 Recover the Smallest Number

    Given a collection of number segments, you are supposed to recover the smallest number from them. Fo ...

  4. 1038 Recover the Smallest Number (30 分)

    1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to r ...

  5. 1.21 贪心入门上午PAT例题题解

    1.B1023 #include<cstdio> int a[10]; int main() { for(int i=0;i<=9;i++) { scanf("%d&quo ...

  6. PAT_A1038#Recover the Smallest Number

    Source: PAT A1038 Recover the Smallest Number (30 分) Description: Given a collection of number segme ...

  7. PAT甲级题解分类byZlc

    专题一  字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...

随机推荐

  1. [翻译] GSProgressView

    GSProgressView 本人极不推荐使用drawRect的方式来绘制下载进度条,无论机器的性能怎么高,使用drawRect用于绘制图形都是低效的. A cute little circular ...

  2. 转移RMS模拟器

    在PowerShell中识别当前 RMS 模拟器 get-SCOMRMSemulator ?移至另一个管理服务器 –首先将一个新的RMS模拟器管理指定为一个变量 $MS = get-scommanag ...

  3. switch与java

    switch结构可以更好的解决等值判断问题switch 选择结构的语法:switch (表达式){case 常量 1://代码块1:break;case 常量 2://代码块2:break;..... ...

  4. CSS学习---css基础知识0105

    CSS, Cascading Style Sheets的简称,中文称为层叠样式表,用来控制网页数据的表现,可以使网页的表现与数据内容分离. 举例:颜色,大小,高度.宽度.内外边距.边框.浮动.定位.字 ...

  5. 深入浅出VisualStudio——使用NuGet来安装AjaxControlToolKit

    使用NuGet可以加速配置Visual Studio 2010的开发环境. 1.创建一个空的ASP.NET web站点项目. 2.右键单击此web 站点,选择Manage NuGet Packages ...

  6. ZT A2DP协议笔记

    A2DP协议笔记 (2013-07-30 10:07:54) 转载▼ 标签: a2dp bluetooth src sink 分类: Bluetooth 1.概述     A2DP(Advanced ...

  7. Eclipse和JDK的安装配置

    工欲善其事,必先利其器.最近开始学习Java语言,必不可少的要先安装一个IDE,我选择了eclipse,下面我们讲讲如何来安装及配置. Step1:工具的下载 这里我们需要用到三个工具安装包,JDK. ...

  8. 021.1 IO流——File类

    ########################################IO流:    IO:用于处理设备上的数据的技术.设备:内存,硬盘,光盘    流:系统资源,Windows系统本身就可 ...

  9. C语言程序员必读的5本书

    本文由 伯乐在线 - programmer_lin 翻译自 fromdev.欢迎加入技术翻译小组.转载请参见文章末尾处的要求. 你正计划着通过看书来学习C语言吗?“书籍是人类最忠诚的朋友“.海明威一定 ...

  10. (七)Linux下的关机与重启命令

    ============================================================================================= 关机与重启命 ...