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

思路:使用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. Python学习---线程/协程/进程学习 1220【all】

    Python学习---线程基础学习 Python学习---线程锁/信号量/条件变量同步1221 Python学习---同步条件event/队列queue1223 Python学习---进程 1225 ...

  2. 沉淀再出发:用python画各种图表

    沉淀再出发:用python画各种图表 一.前言 最近需要用python来做一些统计和画图,因此做一些笔记. 二.python画各种图表 2.1.使用turtle来画图 import turtle as ...

  3. matlab 波纹扭曲

    % 波纹扭曲 img=imread('pic.jpg'); img=im2double(img); [h,w,c]=size(img); ratio=600/(h+w); img=imresize(i ...

  4. Hydra初识

    Hydra词出自希腊神话,原意是是九头蛇,后被赫拉克罗斯所杀,成为赫拉克罗斯的12件伟大功绩之一.而在计算机上HC-HYDRA是一个支持多种网络服务的非常快速的网络登陆破解工具.支持ssh,RDP,M ...

  5. 6、Node.js 事件循环

    #########################################################################################Node.js 事件循 ...

  6. Linux 系统性能监控命令详解

    Linux 系统性能监控命令详解 CPU MEMORY IO NETWORK LINUX进程内存占用查看方法 系统负载过重时往往会引起其它子系统的问题,比如:->大量的读入内存的IO请求(pag ...

  7. Server Host Cannot be null解决方法

    在用打开Services Directory application 或者访问 某个已发布的地图服务时,出现"Server Host Cannot be null"的错误. 问题的 ...

  8. JavaScript的DOM_动态加载脚本和样式

    一.动态加载脚本 当网站需求变大,脚本的需求也逐步变大.我们就不得不引入太多的 JS 脚本而降低了整站的性能,所以就出现了动态脚本的概念,在适时的时候加载相应的脚本. 1.动态加载js文件 比如:我们 ...

  9. 环境变量、block、修饰符:block对环境变量的引用和修改需要通过修饰符来限定

    环境变量.block.修饰符:block对环境变量的引用和修改需要通过修饰符来限定. http://www.cnblogs.com/fengmin/p/5816580.html - (NSUInteg ...

  10. UVa 1515 - Pool construction(最小割)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...