Codeforces Round #372 (Div. 2) B

Description

ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice.

Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him?

Input

The first and only line of the input contains a single string s (1 ≤ |s| ≤ 50 000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet (‘A‘-‘Z‘) or is a question mark (‘?‘), where the question marks denotes the letters that ZS the Coder can‘t remember.

Output

If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print  - 1 in the only line.

Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters.

If there are multiple solutions, you may print any of them.

Examples

input

ABC??FGHIJK???OPQR?TUVWXY?

output

ABCDEFGHIJKLMNOPQRZTUVWXYS

input

WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO

output

-1

input

??????????????????????????

output

MNBVCXZLKJHGFDSAQPWOEIRUYT

input

AABCDEFGHIJKLMNOPQRSTUVW??M

output

-1

Note

In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such asABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS.

In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is  - 1.

In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer

题意:给出字符串,如果字符串中有长度为26的子串,且子串中的‘?’经过替换可以刚刚好包含26个字母,就输出整个替换后的字符串

解法:首先小于26的直接-1,然后我们依次截取26长度的字符串进行测试,如果可以替换成功,则另外的‘?’一并取A(可以任意,反正有一个子串已经满足要求了),然后输出整个字符串

另外替换可以用map标记,缺失哪个字母就加哪个,然后标记出现过

#include <bits/stdc++.h>
using namespace std;
string s;
map<int,int>q;
int main()
{
    cin>>s;
    if(s.length()<26)
    {
        cout<<"-1"<<endl;
        return 0;
    }
    else
    {
        string sss="";
        int flag=0;
        string ss;
        int i;
        for(i=0;i<s.length()-25;i++)
        {
            ss=s.substr(i,26);
            flag=0;
         //   cout<<ss<<endl;
            for(int z=0;z<26;z++)
            {
                if(q[ss[z]-‘A‘]&&ss[z]!=‘?‘)
                {
                    flag=1;
                }
                else if(ss[z]==‘?‘)
                {
                    q[27]=1;
                }
                else if(ss[z]<=‘Z‘&&ss[z]>=‘A‘)
                {
                    q[ss[z]-‘A‘]=1;
                }
            }
            //cout<<flag<<"A"<<endl;
            if(flag==0)
            {
                for(int g=0;g<26;g++)
                {
                    if(ss[g]==‘?‘)
                    {
                        for(int h=0;h<26;h++)
                        {
                            if(!q[h])
                            {
                                sss+=(‘A‘+h);
                                //printf("%c",‘A‘+h);
                                q[h]=1;
                                break;
                            }
                        }
                    }
                    else if(ss[g]!=‘?‘)
                    {
                        sss+=ss[g];
                       // cout<<ss[i]<<"^"<<endl;;
                    }
                }
                break;
            }
            else
            {
                q.clear();
            }
           // cout<<flag<<endl;
        }
        if(flag)
        {
            cout<<"-1"<<endl;
        }
        else
        {
            for(int l=0;l<i;l++)
            {
                if(s[l]==‘?‘)
                    cout<<"A";
                else
                    cout<<s[l];
            }
            cout<<sss;
            for(int l=i+26;l<s.length();l++)
            {
                if(s[l]==‘?‘)
                    cout<<"A";
                else
                    cout<<s[l];
            }
        }
    }
    return 0;
}

  

时间: 2024-10-14 16:31:09

Codeforces Round #372 (Div. 2) B的相关文章

Codeforces Round #372 (Div. 1) B. Complete The Graph

题目链接:传送门 题目大意:给你一副无向图,边有权值,初始权值>=0,若权值==0,则需要把它变为一个正整数(不超过1e18),现在问你有没有一种方法, 使图中的边权值都变为正整数的时候,从 S 到 T 的最短路恰好等于 L. 若没有输出 "NO",否则输出 "YES",同时输出新图中的所有边权值. 题目思路:二分+最短路(spfa or dijkstra) 闲谈:先%一发杜教,思路来源于看他的代码.然后蒟蒻spfa 982ms,杜教 dijkstra 93m

Codeforces Round #372 (Div. 2) A

Description ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≤ c, jus

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我

[Codeforces] Round #352 (Div. 2)

人生不止眼前的狗血,还有远方的狗带 A题B题一如既往的丝帛题 A题题意:询问按照12345678910111213...的顺序排列下去第n(n<=10^3)个数是多少 题解:打表,输出 1 #include<bits/stdc++.h> 2 using namespace std; 3 int dig[10],A[1005]; 4 int main(){ 5 int aa=0; 6 for(int i=1;;i++){ 7 int x=i,dd=0; 8 while(x)dig[++dd

Codeforces Round #273 (Div. 2)

Codeforces Round #273 (Div. 2) 题目链接 A:签到,仅仅要推断总和是不是5的倍数就可以,注意推断0的情况 B:最大值的情况是每一个集合先放1个,剩下都丢到一个集合去,最小值是尽量平均去分 C:假如3种球从小到大是a, b, c,那么假设(a + b) 2 <= c这个比較明显答案就是a + b了.由于c肯定要剩余了,假设(a + b)2 > c的话,就肯定能构造出最优的(a + b + c) / 3,由于肯定能够先拿a和b去消除c,而且控制a和b成2倍关系或者消除

Codeforces Round #339 (Div. 2) B. Gena&#39;s Code

B. Gena's Code It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, f