[pat]1038. Recover the Smallest Number (30)

https://www.patest.cn/contests/pat-a-practise/1038

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

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

int main(){
	vector<string> vnum;
	int n;
	cin>>n;
	for(int i = 0; i < n; i++){
		string a;
		cin>>a;
		vnum.push_back(a);
	}
	sort(vnum.begin(), vnum.end(), cmp);
	string res = "";
	for(int i = 0; i < vnum.size(); i++){
		res += vnum[i];
	}
	string::iterator it = res.begin();
	while(it != res.end() && '0' == *it)
		it++;
	res.erase(res.begin(), it);
	if(res.size() == 0) res = "0";
	cout<<res<<endl;
	system("pause");
	return 0;
}


你可能感兴趣的:(C++,pat,OJ)