首页 > 其他 > 详细

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

时间:2016-05-23 18:43:58      阅读:124      评论:0      收藏:0      [点我收藏+]

注意前导零的消去。

#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;

string s[10000+10];
int n;

bool cmp(const string &a, const string &b)
{
    return a+b<b+a;
}

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++) cin>>s[i];
    sort(s+1,s+1+n,cmp);
    string ans;
    for(int i=1;i<=n;i++) ans=ans+s[i];

    int flag=0;

    for(int i=0;i<ans.size();i++)
    {
        if(ans[i]!=0)
        {
            flag = 1;
            for(int j=i;j<ans.size();j++) cout<<ans[j];
            break;
        }
    }

    if(flag==0) cout<<"0";
    cout<<endl;
    return 0;
}

 

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

原文:http://www.cnblogs.com/zufezzt/p/5520968.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!