题意:

输入一个正整数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 分)的更多相关文章

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

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

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

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

  3. PAT 甲级 1038 Recover the Smallest Number

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

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

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

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

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

  6. 1038 Recover the Smallest Number (30分)(贪心)

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

  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

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

  9. 1038. Recover the Smallest Number (30) - 字符串排序

    题目例如以下: Given a collection of number segments, you are supposed to recover the smallest number from ...

随机推荐

  1. mac 电脑安装express、npm…… 报 ‘Missing write access to /usr/local/lib/node_modules’错误解决办法

    mac电脑安装express框架.npm…… 报 Missing write access to /usr/local/lib/node_modules 错误 终端输入sudo chown -R $U ...

  2. red hat 报错:apt-get:找不到命令

    Linux有两个系列:一个是RedHat系列,一个是Debian系列. RedHat系列:Redhat.Centos.Fedora等 Debian系列:Debian.Ubuntu等 RedHat 系列 ...

  3. python3中的正则表达式

    精确匹配: \d: 匹配一个数字     \w: 匹配一个字母或数字     . : 匹配任意一个字符     \s: 匹配一个空格(包括tab等空白符) 匹配变长的字符:     * : 匹配任意个 ...

  4. Educational Codeforces Round 70 (Rated for Div. 2) 题解

    比赛链接:https://codeforc.es/contest/1202 A. You Are Given Two Binary Strings... 题意:给出两个二进制数\(f(x)\)和\(f ...

  5. 深入delphi编程理解之消息(六)无窗口单元消息的创建、接受及dispatch模式编程

    一.程序界面 二.程序代码 (一).主界面代码 //========================================================================== ...

  6. pyqt5 通过QLinearGradient 绘制取色板

    要绘制HSV取色板,一般通过绘制前景色和背景色的方式实现,先绘制前景,然后绘制背景,前景是HSV颜色空间,从左到右,背景是亮度,从上到下,xs和ys是鼠标的当前的位置. def graphicsVie ...

  7. 【visio】 设计

    1."设计" 包含了 页面.布局和主题相关设置 2."页面设置" 包含:打印.绘制区域.打印区域.页面缩放.页属性以及替换文字. 替换文字 放在页面设置里,这个 ...

  8. IIS-反向代理简介

    参考:https://www.williamlong.info/archives/5353.html 反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后 ...

  9. Jmeter_正则表达式提取器_提取单组数据

    1.用处:提取登录信息/获取session或者token数值 2.举例:获取登录结果的获取:msg":"登录成功" 这个数据 3.HTTP->后置处理器->正 ...

  10. 开放应用模型操作指南(一)| 云服务一键接入 OAM 体系

    作者 | 邓洪超  阿里云容器平台软件工程师 导读:Open Application Model(OAM)是阿里云联合微软等国际顶级技术团队联合发布的开放应用模型技术.旨在通过全新的应用定义.运维.分 ...