1. 程式人生 > >Party Games

Party Games

#include <iostream>
#include <string>
#include<algorithm>
using namespace std;

int main()
{
    int T,n,i,j;
    while(cin>>T&&T)
    {
        getchar();
        string str[1001];
        for(i=0;i<T;i++)
            getline(cin,str[i]);
        sort(str,str+T);
        string a=str[T/2-1];
        string b=str[T/2];
        string c;
        n=a.length()<b.length()?a.length():b.length();
        j=0;
        for(i=0;i<a.length()&&i<b.length();i++)
        {
          if(a[i]==b[i])
             {
                 c+=a[i];
             }
          else
            {
             if(i==a.length()-1)
                {
                    c+=a[i];
                }
            else if(b[i]-a[i]>1||i!=b.length()-1)
                {
                c+=(a[i]+1);
                break;
                 }
            else
                {
                c+=a[i];
                for(j=i+1;j<a.length();j++)
                {
                        if(j==a.length()-1||a[j]=='Z')
                        {
                            c+=a[j];
                        }
                    else
                        {
                        c+=(a[j]+1);
                        break;
                         }
                }

                break;
            }
        }
    }
    cout<<c<<endl;
    }
}