PAT_A1038#Recover the Smallest Number
Source:
Description:
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 (≤) followed by Nnumber 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. Notice that the first digit must not be zero.
Sample Input:
5 32 321 3214 0229 87
Sample Output:
22932132143287
Keys:
- 贪心
Code:
/*
Data: 2019-07-23 18:47:04
Problem: PAT_A1038#Recover the Smallest Number
AC: 16:22 题目大意:
给几个数,求拼成的最小数
*/
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
const int M=1e4+;
string s[M]; bool cmp(string a, string b)
{
return a+b < b+a;
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif int n;
scanf("%d", &n);
for(int i=; i<n; i++)
cin >> s[i];
sort(s,s+n,cmp);
string ans="";
for(int i=; i<n; i++)
ans += s[i];
while(ans.size()> && ans[]=='')
ans.erase(,);
cout << ans; return ;
}
PAT_A1038#Recover the Smallest Number的更多相关文章
- 把数组排成最小的数/1038. Recover the Smallest Number
题目描述 输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个.例如输入数组{3,32,321},则打印出这三个数字能排成的最小数字为321323. Give ...
- 1038. Recover the Smallest Number (30) - 字符串排序
题目例如以下: Given a collection of number segments, you are supposed to recover the smallest number from ...
- A1038. Recover the Smallest Number
Given a collection of number segments, you are supposed to recover the smallest number from them. Fo ...
- PAT甲1038 Recover the smallest number
1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to r ...
- 1038 Recover the Smallest Number (30 分)
1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to r ...
- 1038. Recover the Smallest Number (30)
题目链接:http://www.patest.cn/contests/pat-a-practise/1038 题目: 1038. Recover the Smallest Number (30) 时间 ...
- PAT 1038 Recover the Smallest Number[dp][难]
1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to r ...
- PAT 甲级 1038 Recover the Smallest Number
https://pintia.cn/problem-sets/994805342720868352/problems/994805449625288704 Given a collection of ...
- pat1038. Recover the Smallest Number (30)
1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...
随机推荐
- MySQL if,ifnull,nullif 函数
一.IF IF(exPR1,expr2,expr3) 如果 expr1 是TRUE (expr1 <> 0 and expr1 <> NULL),则 IF()的返回值为expr ...
- IOS 创建目录/文件夹
•IOS 应用目录简介 个文件夹:Documents, Library和 tmp.Library包含Caches.Preferences目录. Documents:应用中用户数据可以放在这里,iTun ...
- java对象属性为date oracle数据库字段为Timestamp 处理方式
解决方案 SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); java.util.Date da ...
- python requests方法post请求json格式处理
方法如下: import requestsimport json data = { 'a': 123, 'b': 456} ## headers中添加上content-type这个参数,指 ...
- gradle打成jar包报错 "错误: 找不到或无法加载主类 App"(已经配置过主类)
文章目录 将gradle打成jar包(包括依赖) 运行jar包 报错 原因(src自己手动创建的) 解决(添加src目录) 将gradle打成jar包(包括依赖) jar { manifest { a ...
- 11. Django及数据库环境搭建
项目背景 我们做功能测试的时候知道,一个产品基本上都会有增删改查功能,对应接口也就是增删改查接口.做了2年接口自动化测试,觉得最难的点应该是数据的初始化,其实测试一个接口.对接口使用单元测试框架.生成 ...
- 6.Jmeter 参数关联设置
Jmeter的参数关联其实就是参数变量的在不同的采样器(sampler)的存储与传递. 如下我们有一个请求例子. 1. 发起下订单(下订单成功后会返回一个订单Id) 2. 针对该订单进行支付(需要 ...
- Java拦截过滤器模式
当我们想要对应用程序的请求或响应进行一些预处理/后处理时,使用截取过滤器设计模式. 在将请求传递到实际目标应用程序之前,在请求上定义和应用过滤器. 过滤器可以进行请求的认证/授权/日志记录或跟踪,然后 ...
- 实习记——《Rethink》
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/gmszone/article/details/30045055 最终能够在和自己的电脑上写下这些字了 ...
- 深入Linux内核架构 - 内核之中数据结构之间的关系图 & 设备驱动程序(转)
内核之中数据结构之间的关系图 设备驱动程序