博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
B. Complete the Word(Codeforces Round #372 (Div. 2)) 尺取大法
阅读量:4948 次
发布时间:2019-06-11

本文共 3491 字,大约阅读时间需要 11 分钟。

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的子字符串

代码如下:

1 #include 
2 #include
3 4 const int Max=5e4+5; 5 char S[Max]; 6 int P[30]; 7 8 int main(){ 9 while(~scanf("%s",S)){10 bool flag=true;11 int len=strlen(S);12 if(len<26){ //长度短于26的直接pass;13 printf("-1\n");14 continue;15 }16 for(int i=0;i<=len-26 && flag;i++){17 int cnt1=0,cnt2=0;18 memset(P,0,sizeof(P));19 for(int j=i;j
='A'&&S[j]<='Z'){21 P[S[j]-'A']++; //记录该子字符串里面有多少个字母;22 }23 else{24 cnt2++; //记录该子字符串里有多少个?;25 }26 }27 for(int j=0;j<26;j++){28 if(P[j]==1) cnt1++; //记录子字符串里每个字母出现的次数;29 }30 if(cnt1+cnt2 == 26){ //判断是否能有一个子字符串能够满足题意;31 int t=0;32 for(int j=i;j

 

 

转载于:https://www.cnblogs.com/Dillonh/p/8490007.html

你可能感兴趣的文章
Linux学习笔记003-目录
查看>>
h5页面宽度设置7.5rem
查看>>
spring IOC 详解
查看>>
第七周作业
查看>>
ecliplse集成SVN
查看>>
1、VMware安装步骤
查看>>
本周学习进度表及时间安排(2017-12-31~2018-1-6)
查看>>
mysql 实行模糊查询 一个输入值匹配多个字段和多个输入值匹配一个字段
查看>>
hdu 1102(最小生成树)
查看>>
JavaScript对象及初识面向对象
查看>>
mac安装nose,command not found:nosetests
查看>>
抓取cntv电视节目表
查看>>
【刷题】洛谷 P3613 睡觉困难综合征
查看>>
操作系统简介
查看>>
过滤器和拦截器的区别
查看>>
jdk 设计模式
查看>>
js对话框弹窗
查看>>
.NET中怎么有效的使用Cache
查看>>
结对学习感想
查看>>
Tomcat源码分析(从启动流程到请求处理)
查看>>