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

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

int main()
{
	int n;
	cin >> n;
	vector<string> num(n);
	for (int i = 0; i < n; i++)
	{
		cin >> num[i];
	}
	sort(num.begin(), num.end(), cmp);
	string result;
	for (int i = 0; i < n; i++)
	{
		result += num[i];
	}
	int i;
	for (i = 0; i < result.size() && result[i] == '0'; i++);
	if (i == result.size())
		cout << 0 << endl;
	else
		cout << result.substr(i) << endl;
}	

你可能感兴趣的:(PAT (Advanced) 1038. Recover the Smallest Number (30))