Test instructions
Give n strings (n is even);
To construct a string so that half of the n string is less than equal to it, and the other half is greater than it;
The string is required to be as small as possible, while the dictionary sequence is small;
Ideas:
Put all the strings in a sequence;
Then take out the middle of the two-string comparison;
Ac
#include <cstdio> #include <cstring> #include <string> #include <algorithm> #include < iostream>using namespace Std;const int N = 1005;string str[n];string res;int n;int Main () {while (scanf ("%d",& n) && N) {getchar (); for (int i = 0; i < n; i++) {getline (cin, Str[i]);} Sort (str, str + n); string a = STR[N/2-1];string b = Str[n/2];res = ""; for (int i = 0; I < a.size () && i < b.size (); i++) {if (a[i] = = B[i]) Res + = A[i];else {if (i = = A.size ()-1) {res + = A[i];} else if ((B[i]-a[i] > 1) | | I! = b.size ()-1) {res + = (A[i] + 1);} else {res + = a[i];for (int j = i + 1; j < A.size (); j + +) {if (j = = A.size ()-1) {res + = A[j];break;} if (a[j]! = ' Z ') {res + = (A[j] + 1); Res + = ' Z ';}} Break;}} cout << res << Endl;}}
UVA1610 (greedy)