1038 Recover the Smallest Number (30)(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 还是得相信锯响就有沫,水大泡倒墙。
/**********************author: yomidate: 18.5.27ps: 可以说是走错了方向了 为什么正确的算法我就是想不到呢答: 您做的题太少了 啊 没脸看我写的东西 直接抄答案了 我会记住答案的技巧的掉进了去前导零的大坑 中间为的零应该保留啊 这个脑子啊一个大数 只去掉 最前面的零而这个数是由多个数拼成的 必须先拼成那个数再去前导零啊 不然那么多的数 去哪个的啊**********************/#include#include #include #include using namespace std;const int maxn = 10010;string str[maxn];string ans = "";int cmp(string a, string b){ return a+b < b+a;}int main(){ int n; cin >> n; for(int i=0; i > str[i]; } sort(str, str+n, cmp); for(int i=0; i b.value;////}int cmp(str a, str b){ return a.value+b.value < b.value+a.value;}int main(){ int n; scanf("%d", &n); int flag = 1; for(int i=0; i > s[i].value; int len = s[i].value.length(); int pos = 0; for(int j=0; j