pat1038. Recover the Smallest Number (30)
1038. Recover the Smallest Number (30)
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)的更多相关文章
- 1038. Recover the Smallest Number (30)
题目链接:http://www.patest.cn/contests/pat-a-practise/1038 题目: 1038. Recover the Smallest Number (30) 时间 ...
- pat 甲级 1038. Recover the Smallest Number (30)
1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...
- PAT 甲级 1038 Recover the Smallest Number (30 分)(思维题,贪心)
1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to ...
- 1038. Recover the Smallest Number (30) - 字符串排序
题目例如以下: Given a collection of number segments, you are supposed to recover the smallest number from ...
- 1038 Recover the Smallest Number (30)(30 分)
Given a collection of number segments, you are supposed to recover the smallest number from them. Fo ...
- PAT Advanced 1038 Recover the Smallest Number (30) [贪⼼算法]
题目 Given a collection of number segments, you are supposed to recover the smallest number from them. ...
- 1038 Recover the Smallest Number (30分)(贪心)
Given a collection of number segments, you are supposed to recover the smallest number from them. Fo ...
- PAT 1038 Recover the Smallest Number (30分) string巧排序
题目 Given a collection of number segments, you are supposed to recover the smallest number from them. ...
- PAT1038. Recover the Smallest Number
//意识到一个重要错误,一直以为atoi,itoa是windows独有的,linux下不可用,直到刚刚... //string+=比strcat好用多了,字符比较也方便的多,但是用scanf读入str ...
随机推荐
- 《Linux内核设计与实现》读书笔记(九)- 内核同步介绍
存在共享资源(共享一个文件,一块内存等等)的时候,为了防止并发访问时共享资源的数据不一致,引入了同步机制. 主要内容: 同步的概念 同步的方法-加锁 死锁 锁的粒度 1. 同步的概念 了解同步之前,先 ...
- java 乱码问题解决方案
java 乱码问题解决方案 一.tomcat: <Connector port="8080" maxThreads="150&qu ...
- Django会话,用户和注册之用户认证
通过session,我们可以在多次浏览器请求中保持数据, 接下来的部分就是用session来处理用户登录了. 当然,不能仅凭用户的一面之词,我们就相信,所以我们需要认证. 当然了,Django 也提供 ...
- 继承&多态
继承: 概念: 基类,超累,父类 访问权限: Public :无限制,自由访问 Private:不可继承 protected :包内,包外,可访问,继承 default:没有指明任何权限下,默认在同一 ...
- iOS开发图片与颜色处理工具
1.根据颜色生成一张图片 /** 根据颜色生成一张图片 @param color 颜色进制 UIColor类型 @return 一张UIImage图片 */ + (UIImage *)createIm ...
- Serialization之BinaryFormatter
前言 BinaryFormatter序列化二进制序列化使用二进制编码来生成精简的序列化,以用于存储或基于套接字的网络流等. 内容 下面通过一个小小的例子来给大家说明什么是BinaryFormatter ...
- zancun
#include<iostream> #include<cstdio> using namespace std; ; int n; int avai[maxn], need[m ...
- rem原理
rem布局实际上就是实现等比缩放 试想,如果我们的元素在不同的屏幕上可以按照相同的比例来进行缩放就好了. rem的计算原理: 试想把屏幕平均分成10份,那么每一份就是1/10,我们选择每一份的大小是1 ...
- luogu2522 [HAOI2011]Problem b
luogu2522[HAOI2011]Problem b 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公 ...
- 解决浏览器location.href重定向失效问题
在[location.href]赋值语句后,添加页面刷新代码[location.reload(true)],参数为[true]这样就等价于F5刷新页面了. 需要注意的是:不能把[location.re ...