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 ...
随机推荐
- 关于最近练习PYTHON代码的一点心得
做测试以来,一直想学习代码,以前也断断续续的学习过,不过都是练习一些基础语法,学习的是菜鸟教程,但是效果不大. 最近在练习CODEWAR里做练习题,慢慢强化自己对一些基本语法的理解,熟悉基本的内置函数 ...
- MYSQL的SQL_CALC_FOUND_ROWS 和count(*)
mysql的SQL_CALC_FOUND_ROWS 和 count(*) 在很多分页的程序中都这样写: SELECT COUNT(*) from `table` WHERE ......; 查出符合 ...
- Linux命令 touch
1.简介 改变文件或者目录的时间,可以更新文件的存取时间(atime,文件内容被读取的时候就会更改的时间)和更改时间(mtime,文件内容被更改是会变更的时间) 2.语法和参数 touch [参数] ...
- A1082 Read Number in Chinese (25 分)
1082 Read Number in Chinese (25 分) Given an integer with no more than 9 digits, you are supposed t ...
- 使用 U 盘装个 winXP 原版镜像玩红警
winXP 自身是不支持 U 盘启动的,所以用 poweriso 直接制作的 U 盘是没用的 可以使用 wintoflash 操作,下载地址: https://wintoflash.en.softon ...
- 力扣算法——135Candy【H】
老师想给孩子们分发糖果,有 N 个孩子站成了一条直线,老师会根据每个孩子的表现,预先给他们评分. 你需要按照以下要求,帮助老师给这些孩子分发糖果: 每个孩子至少分配到 1 个糖果.相邻的孩子中,评分高 ...
- MFC DLL 导出函数的定义方式
一直在鼓捣DLL,每天的工作都是调试一个一个的DLL,往DLL里面添加自己的代码,但是对于DLL一直不太了解啊!今天一查资料,才发现自己对于DLL编写的一些基本知识也不了解.要学习,这篇文章先总结DL ...
- 【题解】Tom的烦恼
题目描述 Tom是一个非常有创业精神的人,由于大学学的是汽车制造专业,所以毕业后他用有限的资金开了一家汽车零件加工厂,专门为汽车制造商制造零件.由于资金有限,他只能先购买一台加工机器.现在他却遇到了麻 ...
- 15-python基础-元组
1.元组的定义 Tuple(元组)与列表类似,不同之处在于元组不能修改. 元组表示多个元素组成的序列. 元组在python开发中,有特定的应用场景. 用于存储一串信息,数据之间使用,分割 元组用()定 ...
- 在MVC4.5.1中使用Ninject
看完Pro ASP.NET MVC5的前14章之后,终于开始了自己的项目搭建. 打算在实际项目中使用Ninject 但是总是出现各种问题.这里记录一下 在书中使用的Ninject的版本是: Insta ...