【PAT甲级】1038 Recover the Smallest Number (30 分)
题意:
输入一个正整数N(<=10000),接下来输入N个字符串,每个字符串包括至多8个字符,均为数字0~9。输出由这些字符串连接而成的最小数字(不输出前导零)。
trick:
数据点0只包含没有0的串。
数据点2,5,6包含最小串全部为0且次小串含有前导零的数据。
如果所有的数字均为0,输出一个0即可。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
string s[];
bool cmp(string a,string b){
string c=a+b;
string d=b+a;
int posc=;
while(c[posc]=='')
++posc;
int posd=;
while(d[posd]=='')
++posd;
if(posc>posd)
return ;
else if(posc<posd)
return ;
else{
if(c<d)
return ;
else
return ;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
for(int i=;i<=n;++i)
cin>>s[i];
sort(s+,s++n,cmp);
int posi=,posj=,flag=;
for(int i=;i<=n;++i){
for(int j=;j<s[i].size();++j)
if(s[i][j]!=''){
flag=;
posi=i;
posj=j;
break;
}
if(flag)
break;
}
if(!flag)
cout<<;
else{
for(int j=posj;j<s[posi].size();++j)
cout<<s[posi][j];
for(int i=posi+;i<=n;++i)
for(int j=;j<s[i].size();++j)
cout<<s[i][j];
}
return ;
}
【PAT甲级】1038 Recover the Smallest Number (30 分)的更多相关文章
- PAT 甲级 1038 Recover the Smallest Number (30 分)(思维题,贪心)
1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to ...
- 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
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. ...
- PAT 1038 Recover the Smallest Number (30分) string巧排序
题目 Given a collection of number segments, you are supposed to recover the smallest number from them. ...
- 1038 Recover the Smallest Number (30分)(贪心)
Given a collection of number segments, you are supposed to recover the smallest number from them. Fo ...
- 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
1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to r ...
- 1038. Recover the Smallest Number (30) - 字符串排序
题目例如以下: Given a collection of number segments, you are supposed to recover the smallest number from ...
随机推荐
- XFire客户端调用CXF服务端(四)
前面章节:http://www.cnblogs.com/xiehongwei/p/8082337.html 已经开发出了CXF服务端,现在用XFire开发客户端调用CXF服务端,代码如下: impor ...
- win10无法登陆SSG进行WEB UI管理
故障描述:尝试登录SSG设备时,无法无法刷出页面,但是设备时可以ping通的(内部接口),可以Telnet上设备,就是无法通过网页登录. 深入测试:win7的系统可以登录,win10的不行,浏览器报协 ...
- 洛谷 P1843 奶牛晒衣服(二分答案)
嗯... 题目链接:https://www.luogu.com.cn/problem/P1843 我们二分枚举时间,看看那些衣服在蒸发后还要用烘干机,则用cnt记录它的时间. 注意w数组在操作中不能变 ...
- tp5的输入和验证
规则和模板 好像要写一样名字,只需要引入模板
- java 工程idea 添加依赖几种方式:
1.add jar and dependecy derictory: 2.add Libary: 点击new library 选取java: 选择libs文件夹作为library: 选择 maven ...
- ASP.NET Core搭建多层网站架构【8.2-使用AutoMapper映射实体对象】
2020/01/29, ASP.NET Core 3.1, VS2019, AutoMapper.Extensions.Microsoft.DependencyInjection 7.0.0 摘要:基 ...
- 小白学 Python 爬虫(28):自动化测试框架 Selenium 从入门到放弃(下)
人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Li ...
- RedisTemplate 获取过期时间的问题
RedisTemplate redisTemplate; Long seconds = redisTemplate.opsForValue().getOperations().getExpire(&q ...
- JavaScript 闭包&基于闭包实现柯里化和bind
闭包: 1 函数内声明了一个函数,并且将这个函数内部的函数返回到全局 2 将这个返回到全局的函数内中的函数存储到全局变量中 3 内部的函数调用了外部函数中的局部变量 闭包简述: 有权访问另一个函数局部 ...
- 吴裕雄--天生自然Numpy库学习笔记:NumPy 从已有的数组创建数组
import numpy as np x = [1,2,3] a = np.asarray(x) print (a) import numpy as np x = (1,2,3) a = np.asa ...