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

Posted Fighting Heart

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT (Advanced Level) 1038. Recover the Smallest Number (30)相关的知识,希望对你有一定的参考价值。

注意前导零的消去。

#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)的主要内容,如果未能解决你的问题,请参考以下文章

PAT Advanced 1038 Recover the Smallest Number (30分)

PAT Advanced 1038 Recover the Smallest Number (30) [贪?算法]

PAT (Advanced Level) 1025. PAT Ranking (25)

PAT Advanced Level 1044

PAT Advanced Level 1043

PAT Advanced Level 1079