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. ...
随机推荐
- redis 3.0 集群__配置文件详解(常用配置)
参考文档 http://www.cnblogs.com/huangjacky/p/3700473.html http://www.cnblogs.com/cxd4321/archive/2012/12 ...
- nginx高性能WEB服务器系列之五--实战项目线上nginx多站点配置
nginx系列友情链接:nginx高性能WEB服务器系列之一简介及安装https://www.cnblogs.com/maxtgood/p/9597596.htmlnginx高性能WEB服务器系列之二 ...
- 简单的XMPP服务器与客户端交互
由客户端发起 C: <stream:stream to="localhost" xmlns="jabber:client" xmlns:stream=&q ...
- ubuntu->错误
1.dpkg *** locked 原因:安装某个包不成功, 可以使用命令 dpkg --configure -a 来重启中断的安装过程 如果屡次安装不成功放弃安装,则删除 lock 2.flashp ...
- HTML-★★★★★表单★★★★★
表单 <form id="" name="" method="post/get" action="负责处理的服务端" ...
- Linux命令-关机命令:shutdown
shutdown -h now 现在马上关机 shutdown -h : 晚上8:30定时关机shutdown -r now 现在马上重起shutdown -r 20:30 晚上8:30定时重起 ca ...
- python学习,day3:示例,进度条
# coding=utf-8 # Author: RyAn Bi import sys,time for i in range(50): sys.stdout.write("#") ...
- PyCharm 通过Github和Git上管理代码
1.最近希望通过github来管理代码,记录下pycharm上的设置,以下是针对windows版本.mac版本略有却别 如图所示 file-settings-Version Control-GitHu ...
- 4:Median of Two Sorted Arrays
here are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two ...
- python+selenium打开浏览器报错问题
报关键字,升级selenium版本 若打开IE浏览器,停在IE界面,无法跳转对应的地址,设置一下IE的页面缩放,设置为100%