# PAT A1038. Recover the Smallest Number (30) 原

阿豪boy

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`

给出若干可能含有前导0的数字串,将他们按照某个顺序拼接,使得生成的数字最小

对数字串s1和s2,如果 s1+s2 < s2+s1那么就将s1放在s2的前面,否则把s2放在s1的前面

``````#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>

using namespace std;
const int MAX = 10010;
string str[MAX];

//如果a+b < b+a 就把a排在前面

int cmp(string a, string b) {
return a + b < b + a;
}
int main(int argc, char *argv[]) {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
cin >> str[i];
sort(str, str + n, cmp);
string ans;
for (int i = 0; i < n; i++)
ans += str[i];
int i = 0;
while (i < ans.size() - 1 && ans[i] == '0')i++;
while (i < ans.size())
printf("%c", ans[i++]);
printf("\n");
return 0;
}``````

### 阿豪boy

hls之m3u8、ts流格式详解

HLS，Http Live Streaming 是由Apple公司定义的用于实时流传输的协议，HLS基于HTTP协议实现，传输内容包括两部分，一是M3U8描述文件，二是TS媒体文件。 1、M3U8文件 用文本方式对媒体文件进行...

souldepth
2016/04/27
12.5K
1
[leetcode]Binary Search Tree Iterator

question Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Calling will return the next smallest number in th......

NineRec
2015/08/27
0
0

2017/11/09
0
0
VK Cup 2018 - Round 1 A. Primal Sport

A. Primal Sport 1.5 seconds 256 megabytes standard input standard output Alice and Bob begin their day with a quick game. They first choose a starting number X0 ≥ 3 and try t......

fire_to_cheat_
03/17
0
0

2012/04/10
157
0

windbg调试C源码级驱动

simpower
31分钟前
0
0
redis快照和AOF简介

32分钟前
0
0

36分钟前
0
0

37分钟前
0
0
qlv视频格式转换器

腾讯视频中的视频影视资源有很多，小编经常在里面下载视频观看，应该也有很多朋友和小编一样吧，最近热播的电视剧也不少，如《香蜜沉沉烬如霜》、《夜天子》还有已经完结的《扶摇》，这么...

41分钟前
0
0