博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT Advanced Level 1038
阅读量:4697 次
发布时间:2019-06-09

本文共 1781 字,大约阅读时间需要 5 分钟。

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

 

 

转载于:https://www.cnblogs.com/AbsolutelyPerfect/p/9096411.html

你可能感兴趣的文章
Jenkins环境拓扑及部署流程
查看>>
Servlet教程
查看>>
ThingsBoard
查看>>
hdu1024 Max Sum Plus Plus 滚动dp
查看>>
python的requests快速上手、高级用法和身份认证
查看>>
c# 整个工程(包括窗体工程)做成dll
查看>>
【转】Asp.Net MVC详解Controller之Filter
查看>>
牛客练习赛24 C PH试纸
查看>>
ERP通用附件管理功能设计与实现
查看>>
【ELK123】ElasticSearch+Kibana
查看>>
石家庄地铁查询
查看>>
c++友元函数和友元类
查看>>
UnrealScript语言基础
查看>>
甭给《程序员》把脉——你不是主编
查看>>
Js获取当前日期时间及其它操作
查看>>
浅析JS模块规范:AMD,CMD,CommonJS
查看>>
Linux diff命令
查看>>
何使用ultraiso软碟通制作u盘启动盘(转载)
查看>>
CentOS6.5 安装python
查看>>
css基本介绍
查看>>