Blue Bridge Cup - Algorithm Improvement - Minimum String

 

At first glance, it seems very simple. When writing, various errors were reported. After carefully understanding the title, I found that the title is really too detailed! !

Sort lexicographically: not each input, compare the size with the previous input, and finally form a string. Instead, after a set of data is entered, the resulting string is minimized! !

Because greed has not yet encountered, so I refer to other people's code:

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
bool cmp(string a, string b) {
	string t1 = a + b, t2 = b + a;
	if (t1 < t2) return true;
	else return false;
	return true;
}
int main()
{
	int num1;
	int num2;
	cin >> num1;
	while (num1--)
	{
		cin >> num2;
		string s[700];
		for (int j = 0; j < num2; j++)
		{
			cin >> s[j];
		}
		sort(s, s + num2, cmp);
		string c;
		for (int i = 0; i < num2; i++) c += s[i];
		cout <<c << endl;	
	}
	return 0;
}

Summary: Read the title carefully!

1. The initialization of the character array, and the sorting of the character array!

2. Customize the sort order!

3. The character array is stored in the vector container <vector>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324179079&siteId=291194637