PAT甲级1038
来源:互联网 发布:ps10.0官方软件下载 编辑:程序博客网 时间:2024/06/11 00:43
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 87Sample Output:
22932132143287
#include<iostream>#include<cstdio>#include<string>#include<algorithm>using namespace std;const int maxn = 10010;string str[maxn];bool cmp(string a, string b){return a + b < b + a;//如果a+b<b+a,就把a排在前面}int main(){int n;cin >> 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];//将排序后的数字串进行拼接}while (ans.size() != 0 && ans[0] == '0'){ans.erase(ans.begin());//去除前导0}if (ans.size() == 0)cout << 0;//去除前导0后为空,输出0else cout << ans;//否则输出结果return 0;}
- PAT(甲级)1038
- 浙大PAT甲级 1038
- PAT甲级1038
- PAT甲级 1038 -- 没有注释
- PAT 甲级
- PAT甲级 A1025.PAT RANKING
- PAT 甲级 1025 PAT Ranking
- PAT(甲级)1003
- PAT(甲级)1004
- PAT(甲级)1005
- PAT(甲级)1006
- PAT(甲级)1007
- PAT(甲级)1008
- PAT(甲级)1009
- PAT(甲级)1010
- PAT(甲级)1011
- PAT(甲级)1012
- PAT(甲级)1013
- Centos服务器被挂马的一次抓马经历
- js print
- pat-bl-1029
- POJ 2993-Emag eht htiw Em Pleh(模拟-根据棋子位置还原棋盘)
- YARN与MapReduce的区别
- PAT甲级1038
- JVM垃圾收集器(1)--G1之前GC方法概览
- Java基本概念-jQuery
- jvm理论-class 再重新认识一下class
- Docker命令大全
- Discuz论坛系统搭建
- SpringMVC中拦截/和拦截/*的区别
- 在一个popwindow里开启另一popwindow
- spark Idea Maven开发环境搭建