题意:

输入一个正整数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. 深入理解python(四)python基础知识之函数

    函数部分 函数部分大概想分成两个部分来讲,第一部分是关于对函数参数的介绍,第二部分是局部变量全局变量和内置变量也就是变量作用域的LGB原则 函数的参数 1.关于形参和实参的问题 第一点要注意的是pyt ...

  2. 为什么要使用wsgi协议

    一个cs模型是由服务器和客户端组成,大多相互情况下也就是服务器端和浏览器之间的通信.通过浏览器请求服务器,然后服务器再响应浏览器. 那么如果浏览器想要请求一个python文件,例如http://127 ...

  3. js 设计模式:观察者和发布订阅模式

    总是把这两个当作同一个模式,但其实是不太一样的,现在重温一下. 观察者模式 观察者直接订阅目标,当目标触发事件时,通知观察者进行更新 简单实现 class Observer { constructor ...

  4. cmake 的使用

    官网教程:https://cmake.org/cmake-tutorial/ 第一个简单的例子 源文件:tutorial.cpp // A simple program that computes t ...

  5. java中对象的初始化问题

    最近又把java编程思想看了看.又有些收获.此书确实不错 java中的初始化相信很多人都知道.但是具体的初始化步骤,初始化几次确不一定.上代码 public class A{ public stati ...

  6. Spring的核心api和两种实例化方式

    一.spring的核心api Spring有如下的核心api BeanFactory :这是一个工厂,用于生成任意bean.采取延迟加载,第一次getBean时才会初始化Bean Applicatio ...

  7. Scrapy模拟登陆

    1. 为什么需要模拟登陆? #获取cookie,能够爬取登陆后的页面 2. 回顾: requests是如何模拟登陆的? #1.直接携带cookies请求页面 #2.找接口发送post请求存储cooki ...

  8. 探索 Python + HyperLPR 进行车牌识别

    概要 HyperLRP是一个开源的.基于深度学习高性能中文车牌识别库,由北京智云视图科技有限公司开发,支持PHP.C/C++.Python语言,Windows/Mac/Linux/Android/IO ...

  9. 获取input type=radio属性的value值

    个人代码1: <div class="form-group" style="width: 250px;margin:0 auto;"> <la ...

  10. Springboot学习:Thymeleaf 语法基础

    详细内容见:Thymeleaf Tutorial 中文翻译,中文文档 参考: thymeleaf官方指南 新一代Java模板引擎Thymeleaf Thymeleaf基本知识 thymeleaf总结文 ...