PAT1038. Recover the Smallest Number

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <string.h>
using namespace std;

bool comp(string a, string b)
{
	string s1 = a+b;
	string s2 = b+a;
	//return lexicographical_compare(s1.begin(),s1.end(),s2.begin(),s2.end());
	return strcmp(s1.c_str(),s2.c_str())<0;
}
int main()
{
	string strNums[10005];
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++)
	{
		cin>>strNums[i];
	}
	sort(strNums,strNums+N,comp);
	string res="";
	for(int i=0;i<N;i++)
		res += strNums[i];

	while(res.length()>0 && res.at(0)=='0')
		res = res.substr(1);
	if(res.length()==0)
		cout<<"0";
	else
		cout<<res;
	return 0;
}



你可能感兴趣的:(PAT1038. Recover the Smallest Number)