UVA1610

思维题  注意下代码中给出的样例就行了

#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i!=n;++i)
#define per(i, n) for(int i=n-1;i>=0;--i)
#define Rep(i, sta, n) for(int i=sta;i!=n;++i)
#define rep1(i, n) for(int i=1;i<=n;++i)
#define per1(i, n) for(int i=n;i>=1;--i)
#define Rep1(i, sta, n) for(int i=sta;i<=n;++i)
#define L rt<<1
#define R rt<<1|1
#define inf (0x3f3f3f3f)
#define llinf (1e18)
#define ALL(A) A.begin(),A.end()
#define SIZE(A) ((int)A.size())
#define MOD (1e9 + 7)
#define PII pair<int,int>
typedef long long i64;
using namespace std;
int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    while(cin >> n && n){
        vector<string> vec(n);
        for(auto &s: vec)
            cin >> s;
        sort(vec.begin(),vec.end());
        int index = n / 2 - 1;
        string pre = vec[index],Next = vec[++index];
        string temp;
        for(int i=0;;++i){
            if(pre[i] == Next[i]){
                temp += pre[i];
            }else{                 
                if(i == pre.length() - 1)
                    temp += pre[i];  
                else if(i != Next.length()-1 || Next[i] > pre[i] + 1)
                    temp += (pre[i] + 1);
                else{// eg:ABCCCE ABD
                    temp += pre[i];
                    for(int j=i+1;j!=pre.length();++j){
                        if(j == pre.length()-1){
                            temp += pre[j];
                            break;
                        }
                        if(pre[j] != 'Z'){
                            temp += (pre[j] + 1);
                            break;
                        }
                        temp += 'Z';
                    }                       
                }
                break;
            }
            if(i == pre.length() - 1 || i == Next.length() - 1)
                break; 
        }
        cout << temp << endl;
    }
    return 0;
}

 

例就好了

posted on 2020-09-09 11:26  chengyulala  阅读(89)  评论(0编辑  收藏  举报

导航