Linux   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了PAT_A1038#Recover the Smallest Number大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

source: PAT A1038 recover the smallest number (30 分) Description: Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given { 32, 321, 3214,
@H_262_14@
@H_262_14@

source:

Description:

Input Specification:

Output Specification:

@H_262_26@Sample Input:

Sample Output:

Keys:

  • 贪心

Code:

 1 /*
 2 Data: 2019-07-23 18:47:04
 3 Problem: PAT_A1038#Recover the smallest number
 4 AC: 16:22
 5 
 6 题目大意:
 7 给几个数,求拼成的最小数
 8 */
 9 #include<cstdio>
10 #include<String>
11 #include<iostream>
12 #include<algorithm>
13 using namespace std;
14 const int M=1e4+10;
15 String s[M];
16 
17 bool cmp(String a,String b)
18 {
19     return a+b < b+a;
20 }
21 
22 int main()
23 {
24 #ifdef    ONLINE_JUDGE
25 #else
26     freopen("Test.txt","r",stdin);
27 #endif
28 
29     int n;
30     scanf("%d",&n);
31     for(int i=0; i<n; i++)
32         cin >> s[i];
33     sort(s,s+n,cmp);
34     String ans="";
35     for(int i=0; i<n; i++)
36         ans += s[i];
37     while(ans.size()>1 && ans[0]==0)
38         ans.erase(0,1);
39     cout << ans;
40 
41     return 0;
42 }
@H_262_14@

大佬总结

以上是大佬教程为你收集整理的PAT_A1038#Recover the Smallest Number全部内容,希望文章能够帮你解决PAT_A1038#Recover the Smallest Number所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:numberpatrecoversmallest
猜你在找的Linux相关文章
其他相关热搜词更多
phpJavaPython程序员load如何string使用参数jquery开发安装listlinuxiosandroid工具javascriptcap