美文网首页PAT
B1038 Recover the Smallest Numbe

B1038 Recover the Smallest Numbe

作者: Tsukinousag | 来源:发表于2020-01-19 20:39 被阅读0次

B1038 Recover the Smallest Number (30分)

把每个字符串按照组合等级排,小的在前,大的在后。

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

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string.h>
#include <cmath>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std;
typedef long long ll;
const int MAX=10005;
const int INF=0x3f3f3f3f;
const int mod=1000000007;
vector<string>vt;
bool cmp(string a,string b)
{
        return a+b<b+a;
}
int main()
{
    int n;
    string ans="";
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        vt.push_back(s);
    }
    sort(vt.begin(),vt.end(),cmp);
    for(int i=0;i<vt.size();i++)
    {
        ans+=vt[i];
    }
        int t=0,len=ans.size();
        while(ans[0]=='0'&&ans.size()>1)
            ans.erase(ans.begin());
        cout<<ans<<endl;
    return 0;
}

相关文章

网友评论

    本文标题:B1038 Recover the Smallest Numbe

    本文链接:https://www.haomeiwen.com/subject/kbhdzctx.html