BC #37 / hdu 5202 Rikka with string · 思维

题解

题意:填补字符串,并判断是不是非回文

将所有?全部替换成a,判断是否为回文串,如果是,将最后一个非中心的a改成b


在这里插入图片描述


#include <bits/stdc++.h>
using namespace std;
int n,m,k;
string s,t;
int main(){
    ios::sync_with_stdio(0);
    
    while(cin>>n){
        cin>>s;
        t="";
        for (int i = 0; i <n; ++i) {
            if(s[i]=='?')t+='a';
            else t+=s[i];
        }
        for (int i = 0; i <n; ++i) {
            if(t[i]!=t[n-i-1]){
                goto ok;
            }
        }

        for (int i = n-1; i>=0 ; i--) {
            if(s[i]=='?' && !(n%2 && i==n/2)){
                t[i]='b';
                goto ok;
            }
        }

        cout<<"QwQ"<<endl;
        continue;
        ok:cout<<t<<endl;
    }
    return 0;
}
发布了34 篇原创文章 · 获赞 0 · 访问量 957

猜你喜欢

转载自blog.csdn.net/Yubing792289314/article/details/104198868
今日推荐