题意:

输入一个正整数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. pwnable.kr-cmd1-Writeup

    MarkdownPad Document *:first-child { margin-top: 0 !important; } body>*:last-child { margin-botto ...

  2. Redis-消息

    Redis 发布订阅(实际开发不使用) Redis 发布订阅(pub/sub)是一种消息通信模式:发送者(pub)发送消息,订阅者(sub)接收消息. Redis 客户端可以订阅任意数量的频道. 下图 ...

  3. 解决sublime不能正常使用python3中的input

    执行以下步骤 1.安装SublimeREPL插件 2.打开快捷键设置运行的快捷键 首选项->快捷设置 {"keys":["ctrl+y+h"], &quo ...

  4. opencv:图像直方图相似性比较

    void hist_compare(Mat src1, Mat src2) { int histSize[] = { 256, 256, 256 }; int channels[] = { 0, 1, ...

  5. opencv python:图像二值化

    import cv2 as cv import numpy as np import matplotlib.pyplot as plt # 二值图像就是将灰度图转化成黑白图,没有灰,在一个值之前为黑, ...

  6. python+树莓派实现IoT(物联网)数据上传到服务器

    环境:raspbian-stretch(2018-06-27) 树莓派:3代B型 1.树莓派设备,需要在野外也能拥有独立联网能力,那必不可少的需要使用物联网模块. 这里使用的是微雪的SIM868通讯模 ...

  7. 【译】高级T-SQL进阶系列 (四)【上篇】:使用游标进行行级别处理

    [译注:此文为翻译,由于本人水平所限,疏漏在所难免,欢迎探讨指正] 原文链接:传送门. 正常来说,使用游标并不是处理记录集的最佳方式.然而当一个经验丰富的程序员第一次开始写TSQL时,他们经常会寻找其 ...

  8. 「BJWC2010」模板严格次小生成树

    题目描述 小 \(C\) 最近学了很多最小生成树的算法,\(Prim\) 算法.\(Kruskal\) 算法.消圈算法等等.正当小\(C\)洋洋得意之时,小\(P\)又来泼小\(C\)冷水了.小\(P ...

  9. JQ - 绑定(on)/解绑(off)事件(浅显的见解)

    on 绑定事件: $("selector").on("click",事件执行函数名); //为 selector 添加 点击事件 $("selecto ...

  10. 红黑树java代码实现

    红黑树 思想源于:https://www.cnblogs.com/nananana/p/10434549.html有解释有图,很清晰(删除时需考虑根节点和兄弟节点的子节点是否存在) package t ...