1038. Recover the Smallest Number (30)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given {32, 321, 3214, 0229, 87}, we can recover many numbers such like 32-321-3214-0229-87 or 0229-32-87-321-3214 with respect to different orders of combinations of these segments, and the smallest number is 0229-321-3214-32-87.

Input Specification:

Each input file contains one test case. Each case gives a positive integer N (<=10000) followed by N number segments. Each segment contains a non-negative integer of no more than 8 digits. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print the smallest number in one line. Do not output leading zeros.

Sample Input:

5 32 321 3214 0229 87

Sample Output:

22932132143287

提交代码

学习网址:http://blog.csdn.net/sinat_29278271/article/details/48047877

里面的传递性是可以证明的

 #include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#include<cmath>
#include<string>
using namespace std;
vector<string> v;
bool cmp(string a,string b){
return a+b<b+a;
}
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
int n,i;
scanf("%d",&n);
string s;
for(i=;i<n;i++){
cin>>s;
v.push_back(s);
}
sort(v.begin(),v.end(),cmp);
s="";
for(i=;i<n;i++){
s=s+v[i];
}
for(i=;i<s.length();i++){
if(s[i]!=''){
break;
}
} if(i==s.length()){
printf("0\n");
}
else{
for(;i<s.length();i++){
cout<<s[i];
}
cout<<endl;
}
return ;
}

pat1038. Recover the Smallest Number (30)的更多相关文章

  1. 1038. Recover the Smallest Number (30)

    题目链接:http://www.patest.cn/contests/pat-a-practise/1038 题目: 1038. Recover the Smallest Number (30) 时间 ...

  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 (30 分)(思维题,贪心)

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

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

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

  5. 1038 Recover the Smallest Number (30)(30 分)

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

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

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

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

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

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

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

  9. PAT1038. Recover the Smallest Number

    //意识到一个重要错误,一直以为atoi,itoa是windows独有的,linux下不可用,直到刚刚... //string+=比strcat好用多了,字符比较也方便的多,但是用scanf读入str ...

随机推荐

  1. winFrom程序更新自动安装

    我就以一个计算字符长度的程序为例子吧界面如下 代码如下 [C#] 纯文本查看 复制代码 ? 01 02 03 04 private void  button1_Click(object sender, ...

  2. BZOJ 1974 [Sdoi2010] auction 代码拍卖会(数位dp)

    题目描述 随着iPig在P++语言上的造诣日益提升,他形成了自己一套完整的代码库.猪王国想参加POI的童鞋们都争先恐后问iPig索要代码库.iPig不想把代码库给所有想要的小猪,只想给其中的一部分既关 ...

  3. 基于vue实现上下滑动翻页效果

    18年年底的时候,一直在做年度报告的H5页面,因为项目需要,需要实现上下滑动翻页,并且上滑的页面比正常页面的比例要缩小一定比例. 效果类似于http://www.17sucai.com/pins/de ...

  4. ghj1222的代码规范

    基本上和notepad++的要求一样. 不定期更新. 1.左大括号换行: int main() { return 0; } 可能有些同志(比如大佬cjh)和我的做法不一样 当一个函数很短的时候可以整个 ...

  5. 「杂录」CQOI 2018 背板记

    背景 经过一天天的等待,终于迎来了\(CQOI2018\),想想\(NOIp\)过后到现在,已经有了快要半年了,曾经遥遥无期,没想到时间一转眼就过去了-- 日志 \(Day0\) 因为明天就要考试了, ...

  6. C++11 特性:成员函数引用限定 (Reference qualifier)

    学了这么多年C++今天拜读scott meyes的more effective cpp第一次看到这种写法... 引用限定可以让成员函数只能被左值对象调用或者只能被右值对象调用: #include &l ...

  7. c#随笔-正则

  8. [BOI2007]Sequence 序列问题 BZOJ1345

    题目描述 对于一个给定的序列a1, …, an,我们对它进行一个操作reduce(i),该操作将数列中的元素ai和ai+1用一个元素max(ai,ai+1)替代,这样得到一个比原来序列短的新序列.这一 ...

  9. kuangbin专题十六 KMP&&扩展KMP HDU2087 剪花布条

    一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢? Input输入中含有一些数据,分别是成对出现的花布条和小 ...

  10. shell脚本安装jdk

    #!/bin/bash BASE_SERVER=192.168.1.11 yum install -y wget wget $BASE_SERVER/soft-all/jdk-7u45-linux-x ...