#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
bool cmp(string a,string b)
{
return a+b<b+a;
}
int main()
{
int n;
cin >>n;
string str[10010];
for(int i =0;i<n;i++)
{
cin>> str[i];
}
sort(str,str+n,cmp);
string ans;
for(int i =0;i<n;i++)
{
ans += str[i];
}
while(ans.size()!=0&&ans[0]=='0')
{
ans.erase(ans.begin());
}
if(ans.size()==0) cout << 0;
else cout << ans;
return 0;
}
使用string库,真的把这题变得很简单了,配合erase() ,begin(),size()函数,使得操作变得简单了很多。比较ans【】都是字符串,记得加上单引号
a1038 recover the smallest number
最新推荐文章于 2024-07-30 18:46:57 发布