B. Complete the Word
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 than26, 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 length26 (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 length26 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.

传送门

题目大意:把所给的字符串中的“?”用A->Z来代替;如果能则输出替换之后的字符串,不能就输出-1.

思路:运用尺取法每次截取一个长度为26的子字符串

代码如下:

 #include <cstdio>
#include <cstring> const int Max=5e4+;
char S[Max];
int P[]; int main(){
while(~scanf("%s",S)){
bool flag=true;
int len=strlen(S);
if(len<){ //长度短于26的直接pass;
printf("-1\n");
continue;
}
for(int i=;i<=len- && flag;i++){
int cnt1=,cnt2=;
memset(P,,sizeof(P));
for(int j=i;j<i+;j++){ //尺取大法;
if(S[j]>='A'&&S[j]<='Z'){
P[S[j]-'A']++; //记录该子字符串里面有多少个字母;
}
else{
cnt2++; //记录该子字符串里有多少个?;
}
}
for(int j=;j<;j++){
if(P[j]==) cnt1++; //记录子字符串里每个字母出现的次数;
}
if(cnt1+cnt2 == ){ //判断是否能有一个子字符串能够满足题意;
int t=;
for(int j=i;j<i+;j++){ //将符合条件的子字符串中的?号换成字母;
if(S[j]=='?'){
for(;t<;t++){
if(P[t]==){
S[j]='A'+t;
t++;
break;
}
}
}
}
flag=false; //只需一组即可;
}
}
for(int i=;i<len;i++){ //剩余的问号随便用字母代替;
if(S[i]=='?'){
S[i]='A';
}
}
if(flag) printf("-1\n");
else printf("%s\n",S);
}
}

B. Complete the Word(Codeforces Round #372 (Div. 2)) 尺取大法的更多相关文章

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

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

  2. Codeforces Round #372 (Div. 2)

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

  3. 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 ...

  4. Codeforces Round #372 (Div. 2) A B C 水 暴力/模拟 构造

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

  5. Codeforces Round #372 (Div. 2) A ,B ,C 水,水,公式

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

  6. 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 ...

  7. Codeforces Round #372 (Div. 1) B. Complete The Graph (枚举+最短路)

    题目就是给你一个图,图中部分边没有赋权值,要求你把无权的边赋值,使得s->t的最短路为l. 卡了几周的题了,最后还是经群主大大指点……做出来的…… 思路就是跑最短路,然后改权值为最短路和L的差值 ...

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

    题目链接:传送门 题目大意:给你一副无向图,边有权值,初始权值>=0,若权值==0,则需要把它变为一个正整数(不超过1e18),现在问你有没有一种方法, 使图中的边权值都变为正整数的时候,从 S ...

  9. 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 ...

随机推荐

  1. Winform 子窗体设置刷新父窗体

    方法1:所有权法 父窗体:Form1    子窗体:Form2 //Form1:窗体代码 //需要有一个公共的刷新方法 public void Refresh_Method() { //... } / ...

  2. 抽象类 C#

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. table与div互相嵌套注意

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...

  4. linux 环境变量配置(node)

    控制台 env 查看当前的环境变量配置 修改/etc/profile文件,在末尾添加以下内容 export NODE_HOME=/usr/local/node //Node所在路径 export PA ...

  5. 【Python】Python之文件操作

    1. file=open('xxx.txt', encoding='utf-8'),open()函数是Python内置的用于对文件的读写操作,返回的是文件的流对象(而不是文件本身,所以使用的方法都是流 ...

  6. 【bzoj4278】[ONTAK2015]Tasowanie 贪心+后缀数组

    题目描述 给定两个数字串A和B,通过将A和B进行二路归并得到一个新的数字串T,请找到字典序最小的T. 输入 第一行包含一个正整数n(1<=n<=200000),表示A串的长度. 第二行包含 ...

  7. BZOJ4028 HEOI2015公约数数列(分块)

    前缀gcd的变化次数是log的,考虑对每一种gcd查询,问题变为查询一段区间是否存在异或前缀和=x/gcd. 无修改的话显然可以可持久化trie,但这玩意实在没法支持修改.于是考虑分块. 对于每一块将 ...

  8. Python高级数据类型模块collections

    collections模块提供更加高级的容器数据类型,替代Python的内置dict,list, set,和tuple  Counter对象 提供计数器,支持方便和快速的计数.返回的是一个以元素为键, ...

  9. 转:浅谈深度学习(Deep Learning)的基本思想和方法

    浅谈深度学习(Deep Learning)的基本思想和方法  参考:http://blog.csdn.net/xianlingmao/article/details/8478562 深度学习(Deep ...

  10. 【题解】SDOI2009Bill的挑战

    这题好像状压的做法比较的无脑?但想记录一下容斥的做法,感觉自己对于容斥简直一无所知.这道题目容斥的解法我也是看了题解才会的.如有雷同,是我看的(*/ω\*)我们可以首先枚举当前字符串与给定的哪 \(k ...