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;
}

  

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

  1. Codeforces Round #372 (Div. 2)

    Codeforces Round #372 (Div. 2) C. Plus and Square Root 题意 一个游戏中,有一个数字\(x\),当前游戏等级为\(k\),有两种操作: '+'按钮 ...

  2. Codeforces Round #372 (Div. 2) A .Crazy Computer/B. Complete the Word

    Codeforces Round #372 (Div. 2) 不知不觉自己怎么变的这么水了,几百年前做A.B的水平,现在依旧停留在A.B水平.甚至B题还不会做.难道是带着一种功利性的态度患得患失?总共 ...

  3. Codeforces 715B & 716D Complete The Graph 【最短路】 (Codeforces Round #372 (Div. 2))

    B. Complete The Graph time limit per test 4 seconds memory limit per test 256 megabytes input standa ...

  4. Codeforces 715A & 716C Plus and Square Root【数学规律】 (Codeforces Round #372 (Div. 2))

    C. Plus and Square Root time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  5. Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))

    A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  6. Codeforces 716B Complete the Word【模拟】 (Codeforces Round #372 (Div. 2))

    B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  7. Codeforces Round #372 (Div. 2) C 数学

    http://codeforces.com/contest/716/problem/C 题目大意:感觉这道题还是好懂得吧. 思路:不断的通过列式子的出来了.首先我们定义level=i, uplevel ...

  8. Codeforces Round #372 (Div. 1) A. Plus and Square Root 数学题

    A. Plus and Square Root 题目连接: http://codeforces.com/contest/715/problem/A Description ZS the Coder i ...

  9. Codeforces Round #372 (Div. 2) C. Plus and Square Root

    题目链接 分析:这题都过了2000了,应该很简单..写这篇只是为了凑篇数= = 假设在第级的时候开方过后的数为,是第级的系数.那么 - 显然,最小的情况应该就是, 化简一下公式,在的情况下应该是,注意 ...

  10. Codeforces Round #372 (Div. 2) C

    Description ZS the Coder is playing a game. There is a number displayed on the screen and there are ...

随机推荐

  1. Java基础(51):Super与this的区别

    1.     子类的构造函数如果要引用super的话,必须把super放在函数的首位. class Base { Base() { System.out.println("Base" ...

  2. linux代码段,数据段,BSS段, 堆,栈(二)

    //main.cpp int a = 0; 全局初始化区  char *p1; 全局未初始化区 main() { int b; 栈 char s[] = "abc"; 栈 char ...

  3. 3D语音天气球(源码分享)——在Unity中使用Android语音服务

    转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 开篇废话: 这个项目准备分四部分介绍: 一:创建可旋转的"3D球":3 ...

  4. paper 54 :图像频率的理解

    我一直在思考一个问题,图像增强以后,哪些方面的特征最为显著,思来想去,无果而终!翻看了一篇知网的paper,基于保真度(VIF)的增强图像质量评价,文章中指出无参考质量评价,可以从三个方面考虑:平均梯 ...

  5. paper 20 :color moments

    图像的颜色特征是很重要的,其中颜色矩也是很重要的一部分.(还有一个关于图像颜色特征的review,对于image color写的比较全面).还有,我要强调一下,本blog上的链接都是Google学术上 ...

  6. redis连接数问题

    redis连接数查看 info client redis连接数满了,不会继续建立连接. 造成redis连接数满了原因有很多. 1.建立新连接不close()的话redis连接不会回归连接池. 显示所有 ...

  7. mtool安装

    先安装python pip.一种python包管理工具. 下面这篇文章讲的很详细.亲测可行. https://ruter.github.io/2015/12/03/Update-python/ git ...

  8. C语言初学者代码中的常见错误与瑕疵(19)

    见:C语言初学者代码中的常见错误与瑕疵(19)

  9. OpenMP的调度

    schedule(static, size) 这是静态调度,如果没有设置size, 默认是根据任务书来决定, 比如我电脑是8核,有26个任务,那么分配后结果是4 4 3 3 3 3 3 3. 因为先分 ...

  10. SQLServer查询速度慢的原因

    查询速度慢的原因很多,常见如下几种:  1.没有索引或者没有用到索引(这是查询慢最常见的问题,是程序设计的缺陷) 2.I/O吞吐量小,形成了瓶颈效应.  3.没有创建计算列导致查询不优化.  4.内存 ...