Recover the Smallest Number

  • 题目
  • AC代码
  • 参考
  • 知识点总结

题目

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 (≤10​4​​ ) 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. Notice that the first digit must not be zero.

Sample Input:

5 32 321 3214 0229 87

Sample Output:

22932132143287

AC代码

#include<bits/stdc++.h>
using namespace std;bool cmp(string x,string y){string xy=x+y,yx=y+x;return xy<yx;
}int main()
{int n,len;cin>>n;string s[n];for(int i=0;i<n;i++){cin>>s[i];len+=s[i].length();}sort(s,s+n,cmp);string ans="";for(int i=0;i<n;i++)ans+=s[i];stringstream ss;int t;ss<<s[n-1];ss>>t;if(t==0){cout<<0;return 0;} int flag=1;for(int i=0;i<ans.length();i++){if(flag&&ans[i]=='0') continue;else flag=0;cout<<ans[i];}
}

参考

Recover the Smallest Number (30) - 字符串排序

知识点总结

  1. stringstream的相关用法
  2. 字符串排序

PAT——Recover the Smallest Number相关推荐

  1. PAT甲级1038 Recover the Smallest Number (30 分):[C++题解]贪心、排列成最小的数、字符串

    文章目录 题目分析 题目来源 题目分析 来源:acwing 分析: 贪心: 对于字符串a和b,如果 a+b < b+a (这里+代表字符串中的连接)代表字典序更小.举例 a = 321 , b ...

  2. PAT甲级:1038 Recover the Smallest Number

    题目描述: Given a collection of number segments, you are supposed to recover the smallest number from th ...

  3. pat1038. Recover the Smallest Number (30)

    1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...

  4. 1038. Recover the Smallest Number (30)

    1038. Recover the Smallest Number (30) 进行排序,注意comp的写法: #include <iostream> #include <vector ...

  5. 1038 Recover the Smallest Number (30分)

    题目 Given a collection of number segments, you are supposed to recover the smallest number from them. ...

  6. PAT-A-1038 Recover the Smallest Number 【贪心】 【二刷】

    贪心算法,最核心的在于贪心策略上 Given a collection of number segments, you are supposed to recover the smallest num ...

  7. A1038 Recover the Smallest Number (30)

    Powered by:NEFU AB-IN Link 文章目录 A1038 Recover the Smallest Number (30) 题意 思路 代码 A1038 Recover the Sm ...

  8. PAT (Advanced Level) 1038. Recover the Smallest Number (30)

    注意前导零的消去. #include <iostream> #include <string> #include <sstream> #include <al ...

  9. 1038 Recover the Smallest Number (30 分)【难度: 中 / 知识点: 贪心 思维】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805449625288704 PAT上的这道题的数据有点弱,其它网站上的数 ...

最新文章

  1. python释放类对象_Python 基本功: 10. 面对对象-类 Class
  2. Spring Cloud Feign的两种使用姿势
  3. 项目: 用c++写一个养成类的游戏【QQ宠物】
  4. JAVA——基于HttpClient的获取帆软FineReport报表爬虫DEMO
  5. 【Qt】2D绘图之图形视图框架(一)
  6. 机器学习从入门到精通50讲(四)-实时数仓应用实践案例
  7. C++ override 关键字用法
  8. 度假式办公环境、值得拥有!珠海金山软件诚聘CV、C++、后端工程师
  9. 小小数据统计(柱状图、折线图、扇形图)
  10. C++之yaml-cpp开源库的使用笔记
  11. 一个批量转换文件编码的python脚本
  12. mysql组合索引与字段顺序
  13. js中定义变量加var与不加var的区别?
  14. 【数字信号调制】基于matlab二进制差分相移键控调制(2DPSK)【含Matlab源码 163期】
  15. Python语音转文字、音频切割、语音识别
  16. 开源车牌数据集CCPD介绍
  17. 杭州计算机及应用不可以落户,90%的城市取消落户限制!附杭州落户超详细攻略...
  18. 破解sublime 3207(2019.6.3更新)
  19. 基于vue+百度地图的多车实时运动及轨迹追踪实现(上帝视角篇)
  20. deepin系统 crontab 执行自动任务

热门文章

  1. 视频教程-ASP.NET酒店客房预订管理系统毕业设计-.NET
  2. Zephry传感器模型介绍和bme240测试
  3. 消息传递神经网络(MPNN)内容及代码实践
  4. HBase的Compact参数设置及数据读写流程剖析-OLAP商业环境实战
  5. 转换blob类型的数据,然后进行下载各种文件,还有各种blob转换的文件类型
  6. Export_Parent父子项目的搭建
  7. 格雷希尔G25A系列快速密封接头让密封更安全可靠
  8. 怎么有效锻炼自己的记忆力?
  9. linux cts运行不起来,CTS测试过程及遇到问题的解决方法
  10. cURL 与 Guzzle 的对比与选用