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. ...
随机推荐
- 对xaml的深入探究(补交作业)
首先,下结论,看完那个外国老师的视频后,5%左右听懂了,分享给大家: 1.理解一下,xaml是特殊的xml,我们可以从代码语法看出,xaml中的打码很类似与html和xml的代码. 2.xaml.cs ...
- handlersocket优缺点
HandlerSocket的优势和特点: 1) 支持多种查询模式 HandlerSocket目前支持索引查询(主键索引和非主键的普通索引均可),索引范围扫描,LIMIT子句,也即支持增 ...
- 2019.2.14 t3 车辆销售
用算法求最大生成树,在并查集合并时,把原本的一个根连向另一个 根改成两个根都连向一个新建的节点,并把当前正在处理的边的权值赋给这个新 节点做点权.这样形成的结构会是一棵树. 一个点的答案大致上是树的根 ...
- js的事件机制
js的事件机制 解释:当我们的行为动作满足了一定的条件后,会触发某事务的执行. 内容: 1.单双击事件 单击:onclick 当鼠标单击时候会触发 双击:ondbclick 当鼠标双击时候会触发 2. ...
- Windows下Anaconda安装 python + tensorflow GPU版
这里首先确认没有安装CPU版本,并默认已经安装了CUDA和Cudnn以及anaconda. 安装gpu版本的tensorflow 接下来需要安装GPU版本的tensorflow: 打开cmd并输入: ...
- python之类与对象(1)
面向对象编程是最有效的软件编写方法之一.编写类时,定义一群对象都有的通用行为.基于类创建对象时,每个对象都自动具备这种通用行为,然后可以根据需要赋予每个对象的独特的个性. 1. 类与对象的语法规范 关 ...
- js获取窗口宽度、高度
1.获取屏幕的高度和宽度(屏幕分辨率): window.screen.height window.screen.width 2.获取屏幕工作区域的高度和宽度(去掉状态栏): window.screen ...
- 推荐 IntelliJ IDEA 牛逼的插件
1. activate-power-mode 和 Power mode II 根据Atom的插件activate-power-mode的效果移植到IDEA上 写代码是整个屏幕都在抖动,activate ...
- Mysql+innodb数据存储逻辑
Mysql+innodb数据存储逻辑. 表空间由段,区,页组成 ibdata1:共享表空间.即所有的数据都存放在这个表空间内.如果用户启用了innodb_file_per_table,则每张表内的数据 ...
- Failed to start NodeManager caused by "/var/lib/hadoop-yarn/yarn-nm-recovery/yarn-nm-state/LOCK: Permission denied"
Hadoop 安装步骤: 0. 安装前准备(节点机器,环境设置,yum源设置) 1. 配置并安装Cloudera-Manager 2. 启动 CM 服务 3. 安装CDH,并配置集群 4. 启动 ...