Complete the Word
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.
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 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个字母排列的子串,则输出填补后的字符串,否则输出-1。用一个数组来标记,记录字母出现的位置,如果一个字母出现了两遍,那么就回到他出现第一次位置的下一位,所有的数据初始化,继续寻找,直到符合要求了跳出循环。
代码:
#include <iostream>
#include <map>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
string a;
int t = ;
int c = ;
int check[] = {};
cin>>a;
int n = ;
for(int i = ;i < a.size();i ++)
{
if(n + c >= )break;
if(a[i] == '?')n ++;
else if(a[i] >= 'A' && a[i] <= 'Z')
{
if(!check[a[i] - 'A'])
{
check[a[i] - 'A'] = i + ;
c ++;
}
else
{
i = check[a[i] - 'A'] - ;
t = i + ;
n = c = ;
memset(check,,sizeof(check));
}
}
}
if(n + c < )cout<<-<<endl;
else
{
int j = ;
for(int i = ;i < a.size();i ++)
{
if(a[i] != '?')cout<<a[i];
else if(i >= t && i <= t + )
{
while(check[j])j++;
cout<<(char)('A'+j);
j ++;
}
else cout<<'A';//无关紧要的可以随意填补,只要保证满足要求的子串填补好了,其他的随便填补,子串一定要是连续的26个
}
}
}
Complete the Word的更多相关文章
- 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 ...
- 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 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 ...
- Complete the Word CodeForces - 716B
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists asubstring ...
- CodeForces 716B Complete the Word
题目链接:http://codeforces.com/problemset/problem/716/B 题目大意: 给出一个字符串,判断其是否存在一个子串(满足:包含26个英文字母且不重复,字串中有‘ ...
- Mou常用快捷键
title: Mou常用快捷键date: 2015-11-08 17:16:38categories: 编辑工具 tags: mou 小小程序猿我的博客:http://daycoding.com Vi ...
- Codeforces Round #370 - #379 (Div. 2)
题意: 思路: Codeforces Round #370(Solved: 4 out of 5) A - Memory and Crow 题意:有一个序列,然后对每一个进行ai = bi - bi ...
- Codeforces水题集合[14/未完待续]
Codeforces Round #371 (Div. 2) A. Meeting of Old Friends |B. Filya and Homework A. Meeting of Old Fr ...
随机推荐
- SpringBoot入门篇--整合mybatis+generator自动生成代码+druid连接池+PageHelper分页插件
原文链接 我们这一篇博客讲的是如何整合Springboot和Mybatis框架,然后使用generator自动生成mapper,pojo等文件.然后再使用阿里巴巴提供的开源连接池druid,这个连接池 ...
- 关于安装php时 --with-mysql命令参数问题
如果是rpm安装mysql则直接写成--with-mysql 如果是编译安装mysql则写成--with-mysql=mysql安装路劲 如果你还没有安装Mysql数据库,可以暂时不编译
- 雷林鹏分享:C# 特性(Attribute)
C# 特性(Attribute) 特性(Attribute)是用于在运行时传递程序中各种元素(比如类.方法.结构.枚举.组件等)的行为信息的声明性标签.您可以通过使用特性向程序添加声明性信息.一个声明 ...
- Vue.js Client-Side Storage;( Web Storage/localStorage)
原文:https://cn.vuejs.org/v2/cookbook/client-side-storage.html LocalStorage (api) my code pen :https:/ ...
- 浅谈Linux
Linux系统最初由芬兰赫尔辛基大学的Andrew S.Tanenbaum写的MINIX操作系统演变而来,这是一个小型操作系统,主要用于教学,1991年1月,Tanenbaum的学生Linus Tor ...
- Python面向对象编程、类
一.面向对象编程 面向对象--Object Oriented Programming,简称oop,是一种程序设计思想.在说面向对象之前,先说一下什么是编程范式,编程范式你按照什么方式来去编程,去实现一 ...
- Couchbase集群
Couchbase集群 http://www.cnblogs.com/sunwubin/p/3426801.html Couchbase服务器可以单独运行,也可以作为集群运行.在Couchbase集群 ...
- unity3d 博客
博客: 1.http://my.csdn.net/caoboya 2.http://my.csdn.net/OnafioO
- 059——VUE中vue-router之路由嵌套在文章系统中的使用方法:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- learning docker steps(5) ----- docker stack 初次体验
参考:https://docs.docker.com/get-started/part5/ stack 技术栈.技术栈是一组相关的服务,它们共享依赖项并且可以一起进行编排和扩展.单个技术栈能够定义和协 ...