Complete the Word CodeForces - 716B
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists asubstring (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.
Example
ABC??FGHIJK???OPQR?TUVWXY?
ABCDEFGHIJKLMNOPQRZTUVWXYS
WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO
-1
??????????????????????????
MNBVCXZLKJHGFDSAQPWOEIRUYT
AABCDEFGHIJKLMNOPQRSTUVW??M
-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 as ABCDEFGHIJKLMNOPQRSTUVWXYZ orABCEDFGHIJKLMNOPQRZTUVWXYS.
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 26that contains all letters of the English alphabet fits as an answer.
题目巴拉巴拉很多 有用的信息不多
题意:给你一个字符串 有没有一个有着连续的长度为26的字串,它包含所有的26个字母
这题就是纯暴力,从第 i 个字符开始搜索看看i+26 符不符合条件
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
char a[];
int b[];
int main() {
while(scanf("%s",a)!=EOF) {
int n=strlen(a),flag1,flag2=;
if (n<) {
printf("-1\n");
continue;
}
for (int i= ; i<n- ; i++ ) {
flag1=;
memset(b,,sizeof(b));
for (int j=i ; j<i+ ; j++) {
if (a[j]>='A' && a[j]<='Z') {
b[a[j]-'A']++;
}
if (b[a[j]-'A']>=) {
flag1=;
break;
}
}
if (!flag1) continue;
flag2=;
for (int j=i ; j<i+ ; j++) {
if (a[j]=='?') {
for (int k= ; k< ; k++) {
if (b[k]==) {
a[j]=k+'A';
b[k]=;
break;
}
}
}
}
if (flag2) break;
}
if (flag2) {
for (int i= ;i<n ;i++){
if (a[i]=='?') printf("A");
else printf("%c",a[i]);
}
printf("\n");
}else printf("-1\n");
}
return ;
}
Complete the Word CodeForces - 716B的更多相关文章
- 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 ...
- Codeforces Round #372 (Div. 2) A .Crazy Computer/B. Complete the Word
Codeforces Round #372 (Div. 2) 不知不觉自己怎么变的这么水了,几百年前做A.B的水平,现在依旧停留在A.B水平.甚至B题还不会做.难道是带着一种功利性的态度患得患失?总共 ...
- codeforces 372 Complete the Word(双指针)
codeforces 372 Complete the Word(双指针) 题链 题意:给出一个字符串,其中'?'代表这个字符是可变的,要求一个连续的26位长的串,其中每个字母都只出现一次 #incl ...
- B. 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 ...
- CodeForces 716B Complete the Word
题目链接:http://codeforces.com/problemset/problem/716/B 题目大意: 给出一个字符串,判断其是否存在一个子串(满足:包含26个英文字母且不重复,字串中有‘ ...
- Complete the Word
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring ...
- CSUST 8.5 早训
## Problem A A - Meeting of Old Friends CodeForces - 714A 题意: 解题说明:此题其实是求两段区间的交集,注意要去除掉交集中的某个点. 题解: ...
- Codeforces水题集合[14/未完待续]
Codeforces Round #371 (Div. 2) A. Meeting of Old Friends |B. Filya and Homework A. Meeting of Old Fr ...
- Codeforces Round #370 - #379 (Div. 2)
题意: 思路: Codeforces Round #370(Solved: 4 out of 5) A - Memory and Crow 题意:有一个序列,然后对每一个进行ai = bi - bi ...
随机推荐
- C#写鞍点问题
题目: 编写程序,找一找一个二维数组中的鞍点(即该位置上的元素值在行中最大,在列上最小.有可能数组没有鞍点). 要求 * 二维数组的大小.数组元素的值在运行时输入: * 程序有友好的提示信息 usin ...
- Windows Server 2016-WinSer2016 Active Directory新增功能
Windows Server 2016 Active Directory 域服务 (AD DS)新增很多功能用来提升Active Directory域及组织环境安全等,并帮助他们面向云的部署或混合部署 ...
- qt事件机制---事件范例
在笔记qt课程04笔记中
- 试着把.net的GC讲清楚(1)
什么是GC? GC(garbage collection)是对内存管理中回收已经不用的内存的一种机制,我们熟知的java和.net都有自己的GC机制,是内存管理的一部分. 为什么会有GC呢?是因为动态 ...
- Visual Studio Code 调整字体大小
{ "editor.fontSize": 14, "window.zoomLevel": 1, } // 将设置放入此文件中以覆盖默认设置 { , , #代码字 ...
- 手机APP中使用history.back()返回没有效果的解决
样式是一个超链接A标签,通过点击事件来达到返回上一页的效果. 所以通常做饭是把A标签的href写成#,然后onClick事件,刚开始我只是当成一个普通点击事件,然后使用JS进行返回. 写法如下: &l ...
- 一步一步从原理跟我学邮件收取及发送 13.mime格式与常见字符编码
在前面的本系列文章中我们已经学会了邮件的发送和收取.但在收取中我们看到的是一串串的乱码,回忆前面的发送过程,我们会奇怪:我们前面的邮件是明文啊.为什么明文的邮件明明也可以正常工作,还要弄乱码似的字符串 ...
- 插入排序实现&&选择排序实现
萌新刚刚开始学习算法,第一步是学习排序,毕竟算法的四大块"排序,查找,图,字符串"里面,排序是第一位的(PS:今天才知道算法提供的只是一个程序编写思路,一直以为是一个函数,难怪传入 ...
- java 堆和栈
转载自 http://blog.csdn.net/peterwin1987/article/details/7571808 博主讲的相当清楚吼吼吼
- iOS 添加WKWebView导致控制器无法释放的问题
在WkWebView与JavaScript交互中,经常会在原生中注入MessageHandler,app中注入MessageHandler的方法 WKWebViewConfiguration *con ...