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& ...
随机推荐
- C++ Primer(6) 模板和泛型编程(上)
问题聚焦: 泛型编程是独立于变量类型的方式编写代码: 模板是泛型编程的基础. 本篇主要介绍模板的基础知识,包括:模板的定义和模板的实例化. 1 模版定义 必要性: Demo int compare(c ...
- Excel英语成绩单
- windows10 彻底卸载 Docker 和 DockerNAT
删除docker程序 记事本新建脚本文件 a.ps1,内容如下: $ErrorActionPreference = "SilentlyContinue" kill -force - ...
- iOS测试基础(命令篇)-iPhone型号及其他信息
首先安装libimobiledevice和ideviceinstaller brew uninstall ideviceinstaller brew uninstall libimobiledevic ...
- 缓存MEMCACHE php调用
在项目中,涉及大访问量时,合理的使用缓存能减轻数据库的压力,同时提升用户体验.即在非实时性的需求的前提下,一小段时间内(若干秒),用于显示的数据从缓存中获取的,而不用直接读取数据库,能有效的减少数据库 ...
- python Queue在两个地方
其一: Source code: Lib/queue.py The queue module implements multi-producer, multi-consumer queues. It ...
- 友盟消息推送api、python sdk问题、测试demo代码
一,友盟消息推送python服务端sdk地址和文档地址 1.sdk地址:http://dev.umeng.com/system/resources/W1siZiIsIjIwMTYvMDgvMTkvMT ...
- 1. Docker基础命令
本文简要介绍Docker的基础命令,目的在于快速入门Dokcer,Docker的完整命令可以参考Docker官方手册. 0. 安装Docker Docker当前分为企业版(Docker Enterpr ...
- docker-7-常用软件的安装
1.总体步骤 搜索镜像 拉取镜像 查看镜像 启动镜像 停止容器 移除容器 2.安装tomcat docker hub上面查找tomcat镜像:docker search tomcat 从doc ...
- 20145216史婧瑶《Java程序设计》第五次实验报告
20145216 实验五<Java网络编程> 实验内容 1.掌握Socket程序的编写 2.掌握密码技术的使用 3.设计安全传输系统 实验要求 1.基于Java Socket实现安全传输 ...