PAT 1038. Recover the Smallest Number
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm> using namespace std; bool mycmp(const string& a, const string& b) {
string ta = a + b;
string tb = b + a; int len = ta.length(); for (int i=; i<len; i++) {
if (ta[i] > tb[i]) {
return false;
} else if (ta[i] < tb[i]){
return true;
}
}
return true;
} bool print_no_leading_zero(string &n) {
int len = n.length();
bool full_zero = true;
int i;
for (i=; i<len; i++) {
if (n[i] != '') {
full_zero = false;
break;
}
}
while (i<len) {
cout<<n[i++];
}
return full_zero;
} int main() {
string is;
int N = ;
cin>>N; vector<string> segs(N);
for (int i=; i<N; i++) {
cin>>segs[i];
} int len = segs.size(); sort(segs.begin(), segs.end(), mycmp); bool zero = true;
if (len > ) {
for (int i=; i<len; i++) {
if (zero) {
zero = print_no_leading_zero(segs[i]);
} else {
cout<<segs[i];
}
} }
if (len < || zero) {
cout<<;
}
cout<<endl;
return ;
}
要不是以前做过还是想不到的
PAT 1038. Recover the Smallest Number的更多相关文章
- PAT 1038 Recover the Smallest Number[dp][难]
1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to r ...
- PAT 1038 Recover the Smallest Number (30分) string巧排序
题目 Given a collection of number segments, you are supposed to recover the smallest number from them. ...
- PAT甲1038 Recover the smallest number
1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to r ...
- pat 甲级 1038. Recover the Smallest Number (30)
1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...
- PAT 甲级 1038 Recover the Smallest Number (30 分)(思维题,贪心)
1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to ...
- 1038 Recover the Smallest Number (30 分)
1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to r ...
- 1038. Recover the Smallest Number (30)
题目链接:http://www.patest.cn/contests/pat-a-practise/1038 题目: 1038. Recover the Smallest Number (30) 时间 ...
- PAT 甲级 1038 Recover the Smallest Number
https://pintia.cn/problem-sets/994805342720868352/problems/994805449625288704 Given a collection of ...
- PAT Advanced 1038 Recover the Smallest Number (30) [贪⼼算法]
题目 Given a collection of number segments, you are supposed to recover the smallest number from them. ...
随机推荐
- [译文]casperjs的API-clientutils模块
casper提供了少量的客户端接口用来进行远程DOM环境注入,通过clientutils模块的ClientUtils类实例中的__utils__对象来执行: casper.evaluate(funct ...
- linux入门 配置网络
我因为有自己的ssr,因此想让虚拟机共享我的ssr,并且不想搞的太麻烦,特此记录一下 1. 获取本机的ip 在命令行里输入ipconfig /all 获取本机IP,如下图所示,我本机ip为10.3.7 ...
- SQL语句之用户管理
SQL语句系列 1.SQL语句之行操作 2.SQL语句之表操作 3.SQL语句之数据库操作 4.SQL语句之用户管理 占坑,待写……
- rest-assured之如何指定请求数据(Specifying Request Data 包括请求参数、请求头、cookie等)
我们除了可以为一个请求指定请求参数之外,还可以指定请求头(header).cookies.请求体(body)以及请求内容类型(content-type)等,下面我们就来一一介绍一下: 一.请求HTTP ...
- SPOJ 1811 Longest Common Substring(求两个串的最长公共子串 || 或者n个串)
http://www.spoj.com/problems/LCS/ 题目:求两个串的最长公共子串 参考:https://www.cnblogs.com/autoint/p/10345276.html: ...
- helloweblogic 官方qq群欢迎加入!
点击加入helloweblogic 官方qq群,大家一起进行中间件技术交流,问题交流,互相帮忙互相学习. 我的网易博客地址:http://fm928.blog.163.com 收到网易博客的邮件,以后 ...
- 2.阿里实人认证 .net 准备工作2 转换demo
1.引入阿里的SDK 2. 搬一下java 的代码 DefaultProfile profile = DefaultProfile.GetProfile( "cn-hangzhou" ...
- openerp学习笔记 对象间关系【多对一(一对一)、一对多(主细结构)、多对多关系、自关联关系(树状结构)】
1.多对一(一对一)关系:采购单与供应商之间的关系 'partner_id':fields.many2one('res.partner', 'Supplier', required=True, sta ...
- (转)linux基本变量学习:位置变量$0 、$1 shift轮替、本地变量、环境变量、特殊变量
原文:http://blog.51cto.com/woyaoxuelinux/1863045 shell: 弱类型编程语言 强:变量在使用前,必须事先声明,甚至还需要初始化: 弱:变量用时声明,甚至不 ...
- Git学习系列之Git产生的背景
不多说,直接上干货! 史上最浅显易懂的Git教程! 为什么要编写这个教程?因为我在学习Git的过程中,买过书,也在网上Google了一堆Git相关的文章和教程,但令人失望的是,这些教程不是难得令人发指 ...