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 ...
随机推荐
- JavaScript prototype原型链介绍
javascript 是一种基于原型的编程 (prototype based programming) 的语言, 而与我们通常的基于类编程 (class based programming) 有很大的 ...
- GetTop(),GetTopLeft()等等
Panel_BattleInfo挂在屏幕最上方 protected override void OnStart() { Vector3 = pos = GetTop(); transform.Find ...
- tensorboard的安装及遇到的问题
1 安装tensorboard 打开anaconda prompt,键入下边的命令: activate tensorflow pip install tensorboard 当执行“activate ...
- java 学习第一篇简单基础
Java基础 Java Java 和C#有着极为相似的语法. 和C#都是面向对象的高级程序语言. JAVA是一个开源,公开的语言,有着极其丰富的开源库和其他资源. JAVA分类 JAVA分SE EE ...
- UWP_开源小程序 水印添加器
前几天写了一个确定水印位置的小博客.决定要写一个添加水印的UWP程序. 目前程序技术方面已经差不多了.所以提上日程
- django中将views.py中的python方法传递给html模板文件
常规的模板渲染 from django.db import models # Create your models here. class ArticalType(models.Model): cap ...
- 读《JavaScript权威指南》笔记(三)--对象
1.对象介绍 对象是JavaScript的基本数据类型.对象是一种复合值:它将很多值(原始值或者其他对象)聚合在一起,可通过名字访问这些值.对象也可看做是属性的无序集合,每个属性都是一个名/值对.属性 ...
- 解读人:董鑫,Disease Development Is Accompanied by Changes in Bacterial Protein Abundance and Functions in a Refined Model of Dextran Sulfate Sodium (DSS)-Induced Colitis
文章中文名:在葡聚糖硫酸钠(DSS)诱导下的结肠炎模型伴随着细菌蛋白质丰度和功能的改变 单位: 1 Helmholtz-Centre for Environmental Research - UFZ, ...
- jmeter - 录制web网页
1. 打开JMeter工具 创建一个线程组(右键点击“测试计划”--->“添加”---->“线程组”) 创建一个http代理服务器(右键点击“工作台”--->“添加”-- ...
- java方法里面生成js弹出框
核心代码:方法参数要有response response.setContextType("text/html;charset=UTF-8"); PrintWrite out = r ...