The details deserve attention.
Note that the vector<string> can be directly sort!
#include <iostream>#include<string>#include<vector>#include<algorithm>using namespaceStd;vector<string>str;intMain () {intN; while(cin>>n&&N) {str.clear (); strings; for(inti =0; I < n; i++) {cin>>s; Str.push_back (s); } sort (Str.begin (), Str.end ()); intLen =str.size (); stringS1 = str[len/2-1]; stringS2 = str[len/2]; Len=s1.size (); intp =0; stringAns ="A";// while(P <Len) { while(Ans[p] <='Z'&& ans < S1) ++ans[p];//more than Z for [, cannot appear in the string if(Ans[p] <='Z'&& ans >= s1 && ans < S2) Break; --Ans[p]; Ans+='A'; ++p; /*ayzz AZ ay[*/ /*While (ans < S1) ++ans[p];//do this, if P is short, then ans "p" will be greater than s1[p] (this is problematic, if S1[P] is Z at this time, it is awkward), p=length, will be equal if (ans < S2) break; ans[p]--; Ans + = "A"; ++p;*/} cout<< ans <<Endl; } return 0;}
uva1610 Party Games