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 ...
随机推荐
- 济南清北学堂游记 Day 1.
快住手!这根本不是暴力! 刷了一整天的题就是了..上午三道题的画风还算挺正常,估计是第一天,给点水题做做算了.. rqy大佬AK了上午的比赛! 当时我t2暴力写挂,还以为需要用啥奇怪的算法,后来发现, ...
- VScode离线安装插件
VScode离线插件的转移 需求:换台电脑用VScode 找到插件安装路径 在本地找.vscode的文件夹,里面的extensions文件夹里都是下载的插件 复制发给其他电脑 在vscode首选项-- ...
- SDN第5次上机作业
SDN第5次上机作业 实验目的 1.搭建如下拓扑并连接控制器 2.下发相关流表和组表实现负载均衡 3.抓包分析验证负载均衡 实验步骤 1.建立以下拓扑,并连接上ODL控制器. 提交要求:ODL拓扑界面 ...
- centos7下安装apache服务器httpd的yum方式安装
转自Clement-Xu的csdn博客 http://blog.csdn.net/clementad/article/details/41620631 Apache在Linux系统中,其实叫&qu ...
- PHP判断SQL语句是否合法:mysqli_error()
假设现在有条update语句,有时候update语句正确,但是受影响的行数是0. 那么怎么判断这条SQL语句到底是否正确?使用 mysqli_error($Conn); create table us ...
- mysql 在一个实例运行情况下再搭建一个实例
配置mysql服务 详细步骤,请参考(http://study.lishiming.net/chapter17.html#mysql), 阿铭只把简单步骤写一下. 根据阿铭提供的地址,假如你已经搭建好 ...
- 报错信息 The jsp:param action must not be used outside the jsp:include, jsp:forward, or jsp:params elements 的原因及解决办法
如果你的代码是这样的话就会报错 <jsp:forward page="02.jsp"></jsp:forward> <jsp:param value= ...
- CentOS常用命令搜集
centos是32或者64位:getconf LONG_BIT
- Opencv 330 如何進行圖像的旋轉?
//圖像旋轉 cv::Mat Transformation(cv::Mat src,int angle) { cv::Mat dst = src.clone(); //中心点 cv::Point ce ...
- Qt 信号如何自动连接槽函数?
on_objectName_signal [static] void QMetaObject::connectSlotsByName(QObject *object) void on_<obje ...