Codeforces 716BComplete the Word

Posted awcxv

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces 716BComplete 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;
}

以上是关于Codeforces 716BComplete the Word的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #716 (Div. 2)

codeforces 716

Complete the Word CodeForces - 716B

CodeForces 716A Crazy Computer

CodeForces 716B Complete the Word

Codeforces Round #716 (Div. 2) A. Perfectly Imperfect Array