UVA 1610-Party Games(聚会游戏)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/PR_sc/article/details/77160895

题目链接

题意 给你一N个字符串 要你构造一个字符串D 满足有n/2个字符串比它大 另外半个比它小
分析 给n组字符串排序。然后取中间的两组进行比较。

#include<bits/stdc++.h>
using namespace std;
string a[1006];
int main (void){
    ios::sync_with_stdio(false);
    int n;
    while(cin>>n && n){
        int arr=0;
        for(int i=0;i<n;i++) cin>>a[i];
        sort(a,a+n);
        string b,w=a[n/2],s=a[n/2-1];
        bool f=true;
        while(f){
            for(int i=0;i<26;i++){
                b=s.substr(0,arr);
                b+=i+'A';
                if(b>=s  && b<w){ f=false; break;}
            }
            arr++;
        }
        cout<<b<<endl;
    }
    return 0;
}

总结紫书上说这道题坑很多,刚开始想到的是先比较s,w两个字符串中的相同元素。
后来发现这么做要考虑得情况有点麻烦。于是想出了这么一个耿直的思路hhhh。

猜你喜欢

转载自blog.csdn.net/PR_sc/article/details/77160895