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. ...
随机推荐
- Chart.js入门教程
Chart.js是一个简单.面向对象.为设计者和开发者准备的图表绘制工具库. 相信大部分人都一样,看到一大筐用文本或者表格形式呈现的数据就头疼.因为这种呈现方式也太无聊了吧...而且这对于我们处理原始 ...
- selenium上传图片
在我们使用selenium的时候碰到上传图片.文件时一般都可以先定位然后直接send_keys,但是有的却不行,selenium也没有提供其它的办法,只能靠第三方软件来解决 我们要借助一个叫AutoI ...
- nginx高性能WEB服务器系列之六--nginx负载均衡配置+健康检查
nginx系列友情链接:nginx高性能WEB服务器系列之一简介及安装https://www.cnblogs.com/maxtgood/p/9597596.htmlnginx高性能WEB服务器系列之二 ...
- Oracle 第三方管理工具整理
Oracle 第三方管理工具整理 1.OB(SI Object Browser) 官方网址: http://www.ctdw.com.cn说明:小软件大功能,个人最爱它的数据库导入.导出功能,一键导入 ...
- 记新人从 excel 文件中读取字典数据踩的一个坑
原本是打算今天分享一下最近学习接口自动化的心得体会,然而在我写模板的时候,却被一个坑拦我大半天,心得体会不得不 延期再分享了.在我无数次调试无数次看log,终于发现并解决这个问题了.下面记录一下踩的坑 ...
- CDQZ Day5
1DP #1题目名称 题目名称匹配块路径染色输入文件名 输入文件名match.in.in.inblock.inpath.inpaint.in输出文件名 输出文件名match.out.out.out.o ...
- Linux下如何将文件下载到指定目录
一.问题描述 当我在搭服务器的时候,发现由于下载的东西太多,所以需要将一些安装包下载到指定的目录下. 二.解决办法 wget -P /usr/test http://download.redis.io ...
- Sum(欧拉降幂+快速幂)
Input 2 Output 2 Hint 1. For N = 2, S(1) = S(2) = 1. 2. The input file consists of multiple test cas ...
- 认识CSS中布局之文档流、浮动、定位以及叠放次序
前端之HTML,CSS(七) CSS CSS布局的核心就是盒子的摆放,即CSS定位.而CSS中定位机制分为:普通流(nomal flow).浮动(float).定位(position). 普通流 普通 ...
- Unity QualitySettings.shadows 阴影
QualitySettings.shadows 阴影 public static ShadowQuality shadows; Description 描述: 要使用的实时阴影类型. 这就决定了应该使 ...