#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的更多相关文章

  1. PAT 1038 Recover the Smallest Number[dp][难]

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

  2. PAT 1038 Recover the Smallest Number (30分) string巧排序

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

  3. PAT甲1038 Recover the smallest number

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

  4. pat 甲级 1038. Recover the Smallest Number (30)

    1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...

  5. PAT 甲级 1038 Recover the Smallest Number (30 分)(思维题,贪心)

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

  6. 1038 Recover the Smallest Number (30 分)

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

  7. 1038. Recover the Smallest Number (30)

    题目链接:http://www.patest.cn/contests/pat-a-practise/1038 题目: 1038. Recover the Smallest Number (30) 时间 ...

  8. PAT 甲级 1038 Recover the Smallest Number

    https://pintia.cn/problem-sets/994805342720868352/problems/994805449625288704 Given a collection of ...

  9. PAT Advanced 1038 Recover the Smallest Number (30) [贪⼼算法]

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

随机推荐

  1. ArchLinux下十八岁的感悟

    这次不写技术文章,谈谈自己.现在我们之间没有博主和来访者的关系,我们就是简单聊聊天.你若愿意,就听我说一说. 或者你可以按下crtl+w退出该页面,博主有其他的技术文章.但我希望你能看看最好可以给我留 ...

  2. c:foreach 使用

    <!--引入--> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" ...

  3. 各种 Python 库/模块/工具

    1 算法 1.1 字符串处理 re 正则表达式的标准库. StringIO / cStringIO 以读写文件的方式来操作字符串(有点类似于内存文件). cStringIO 是 C 语言实现的,提供高 ...

  4. js数组的常用操作

    数组合并 var arr=[1,"abc","张三","122"]; var b=["今天天气不错","适合学 ...

  5. Watchbog挖矿病毒程序排查过程

    第1章 情况 1)服务器收到cpu报警,cpu被占用达到100%,登录服务器查看,发现cpu被一个watchbog的进程占满了,如下图所示: 2)并且无论如何都杀不掉,用kill杀掉后,其还是会隔一会 ...

  6. windows本地提权——2003笔记

    windows主机 用户有三种:Users,Administrator,System 本地拥有administrator权限用户提权到system用户 win2003: at命令 系统调度任务的指令, ...

  7. my.等级限制

    1.20190405 “春之恋曲 4月5日双平台新服开服公告”,20190426  上去新建了一个号  发现等级限制是 66级(2天后开启新等级) 20190412 “胭脂雪 4月12日双平台新服开服 ...

  8. MongoDB基本增删改查操作-mongo shell

    基础 1.查看所有数据库: show dbs 2.选择数据库: use test 3.查看数据库中有哪些集合: show collections 如下图: 查询 1.查看集合中有哪些数据,其中abc为 ...

  9. Docker安装及常用操作

    Docker简介: Docker是一个轻量级容器技术,类似于虚拟机技术,但性能远远高于虚拟机,Docker支持将软件编译成一个镜像(image),在这个镜像中做好对软件的各种配置,然后可以运行这个镜像 ...

  10. spring项目中aop的使用

    AOP:是一种面向切面的编程范式,是一种编程思想,旨在通过分离横切关注点,提高模块化,可以跨越对象关注点.Aop的典型应用即spring的事务机制,日志记录.利用AOP可以对业务逻辑的各个部分进行隔离 ...