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. 乱谈zip、rar文件格式

    作者:马健邮箱:stronghorse_mj@hotmail.com发布:2006.11.21最近更新:2006.11.25 目录一.目录表(TOC)与分卷(Volume)二.固实(solid)压缩方 ...

  2. table 和 div 简单布局

    table 简单布局 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// ...

  3. github分支管理

    一. 需要创建的分支 1.master 主分支 2.dev 开发分支 3.bug 修改bug分支 4.release 预发布分支 二.分支使用 1.在master上创建dev,bug,release分 ...

  4. java volatile 关键字(转)

    volatile这个关键字可能很多朋友都听说过,或许也都用过.在Java 5之前,它是一个备受争议的关键字,因为在程序中使用它往往会导致出人意料的结果.在Java 5之后,volatile关键字才得以 ...

  5. git commit失败

    1.使用命令  git rm test.txt 删除版本库中文件, 下一步:git commit 提交 出现如图: 这是因为没有同时提交信息,即:git commit -m "这里是信息&q ...

  6. DP【洛谷P3135】[USACO16JAN]堡哞Fort Moo

    [洛谷P3135][USACO16JAN]堡哞Fort Moo Bessie和她的朋友Elsie正在建筑一个堡垒,与任何一个好的堡垒一样,这个需要一个强固的框架.Bessie想造一个轮廓是1m宽的空心 ...

  7. oracle Date format日期和月份不补0

    格式化日期,日,月只有一位小数的只显示一位,不自动加0,在dd/mm 前面加上fm即可去掉前面的0 如:select to_char(t,'YYYY/fmMM/fmDD') from testdata ...

  8. pycharm加开头注释

    选择 File and Code Templates -> Files -> Python Script #!/usr/bin/env python # encoding: utf-8 ' ...

  9. shell控制流程

    #!/bin/bash #存储为a.sh == ] then #参数正确,返回0 else #参数错误,返回1 fi #!/bin/bash #存储为b.sh echo $? $ . ./a.sh $ ...

  10. [转]Groovy One Liners to Impress Your Friends

    Link:http://arturoherrero.com/2011/06/04/10-groovy-one-liners-to-impress-your-friends/ I find that c ...