题意:

输入一个正整数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. Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException

    实体类缺少无参构造方法,序列化对象需要无参构造方法 @NoArgsConstructor

  2. Gradle是什么?

    Gradle是什么? Gradle是一个基于Apache Ant和Apache Maven概念的项目自动化构建工具.它使用一种基于Groovy的特定领域语言(DSL)来声明项目设置,抛弃了基于XML的 ...

  3. 《深入理解Java虚拟机》读书笔记四

    第五章 调优案例分析与实战

  4. yii2.0 构造函数

    public function init() { parent:: init(); }

  5. DAG 计数

    以下方法都是按照这个套路: 考虑一个不一定连通的 DAG ,你枚举一些零度点(拓扑序第一层)集合 \(S\),这些点之间不能连边,这些点跟剩下点(点集为 \(T\),\(|S| \cup |T| = ...

  6. PCC值average pearson correlation coefficient计算方法

    1.先找到task paradise 的m1-m6: 2.根据公式Dy=D1* 1/P*∑aT ,例如 D :t*k1   a:k2*k1: Dy :t*k2 Dy应该有k2个原子,维度是t: 3.依 ...

  7. Django中的path函数

    path( )作用:解析URL地址 path( ) 标准语法: (<>为必须的参数,[]为可选参数) path(<route>, <view>, [name=Non ...

  8. C语言:根据以下公式计算s,s=1+1/(1+2)+1/(1+2+3)+...+1/(1+2+3+...+n) -在形参s所指字符串中寻找与参数c相同的字符,并在其后插入一个与之相同的字符,

    //根据一下公式计算s,并将计算结果作为函数返回值,n通过形参传入.s=1+1/(1+2)+1/(1+2+3)+...+1/(1+2+3+...+n) #include <stdio.h> ...

  9. excel 练习玩具统计项目组excel日报

    import xlrd import xlwt import os,time import json from xlrd import xldate_as_tuple from datetime im ...

  10. 刷题64. Minimum Path Sum

    一.题目说明 题目64. Minimum Path Sum,给一个m*n矩阵,每个元素的值非负,计算从左上角到右下角的最小路径和.难度是Medium! 二.我的解答 乍一看,这个是计算最短路径的,迪杰 ...