• 【Codeforces 716B】Complete the Word


    题目链接

    【题解】

    当时竟然用线段树做的这题。。。 遍历每个位置。 看看每个位置开始的26个除了问号的字母有没有重复的。 没有的话就ok。 然后按顺序放每个字母就好

    【代码】

    #include <iostream>
    #include <cstdio>
    using namespace std;
    
    string s;
    int temp[100];
    
    void _nextAlpha(char &key,int i){
        while (key<='Z' && temp[key-'A']==i) key++;
    }
    
    int main(){
        ios::sync_with_stdio(0),cin.tie(0);
        cin >> s;
        int len = s.size();
        for (int i = 0;i < len;i++){
            if (i+26-1>=len) break;
            bool ok = true;
            for (int j = i;j <= i+26-1 && j<len;j++){
                if (s[j]=='?') continue;
                if (temp[s[j]-'A']==(i+1)){
                    ok = false;
                    break;
                }else{
                    temp[s[j]-'A'] = (i+1);
                }
            }
            if (ok){
                char key = 'A';
                _nextAlpha(key,i+1);
                for (int j = i;j <= i+26-1 && j<len;j++){
                    if (s[j]=='?'){
                        s[j]=key;
                        temp[key-'A']=i+1;
                        _nextAlpha(key,i+1);
                    }
                }
                for (int i = 0;i < len;i++){
                    if (s[i]=='?') s[i]='A';
                }
                cout<<s<<endl;
                return 0;
            }
        }
        puts("-1");
    	return 0;
    }
    
    
    
  • 相关阅读:
    EasyUI tab
    CC和他的AE86
    Spreading the Wealth UVA
    Ultra-QuickSort POJ
    区间完全覆盖问题(贪心)
    Mod Tree HDU
    Snakes and Ladders LightOJ
    There is no SSR CSU
    X问题 HDU
    斐波那契数列
  • 原文地址:https://www.cnblogs.com/AWCXV/p/12240872.html
Copyright © 2020-2023  润新知