看似简单的所谓坑题,其实不坑,只是需要细致周密的考虑以及造数据debug的能力,而这正是acmer必备的素质。
显然我还不是合格的acmer...这题卡了我好几天。。。
#include<bits/stdc++.h> #define REP(i,a,b) for(int i=a;i<=b;i++) #define MS0(a) memset(a,0,sizeof(a)) using namespace std; typedef long long ll; const int maxn=1100; const int INF=1<<29; string s[maxn],ans; int n; int main() { freopen("in.txt","r",stdin); while(cin>>n,n){ REP(i,1,n) cin>>s[i]; sort(s+1,s+n+1); string a=s[n/2],b=s[n/2+1]; int la=a.size(),lb=b.size(); ans=""; if(la==lb){ int i=0; int tag=0; while(i<la){ if(a[i]==b[i]) ans+=a[i]; else{ if(i==la-1) ans+=a[i]; else ans+=a[i]+1; break; } i++; } } else if(la<lb){ int i=0; while(i<la){ if(a[i]==b[i]) ans+=a[i]; else{ if(i==la-1) ans+=a[i]; else ans+=a[i]+1; break; } i++; } } else{ int tag=0; REP(i,0,lb-1){ if(a[i]==b[i]) ans+=a[i]; else{ if(i==lb-1&&a[i]+1==b[i]) tag=1,ans+=a[i]; else ans+=a[i]+1; break; } } if(tag){ REP(i,lb,la-1){ if(a[i]=='Z') ans+=a[i]; else{ if(i==la-1) ans+=a[i]; else ans+=a[i]+1; break; } } } } cout<<ans<<endl; } return 0; } /** 4 FRED SAM JOE MARGARET 2 FRED FREDDIE 2 JOSEPHINE JERRY 2 LARHONDA LARSEN 2 AAAA AAAB 2 AAAAZZZ BBBB 2 AABAAAZZA AAAAAA 2 AAAB AAAAZAZ 2 AZ B 2 AB Z 2 AC BB 2 A BA 2 AA B 2 ZZZAZZZZZ ZZZZ */