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

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

题目链接:

  http://codeforces.com/contest/716/problem/B

题目大意:

  给你一个长度为N(N<=100000)只含大写字母和'?'的字符串,其中'?'可以被任意大写字母替换,问这个字符串是否能够含有一个连续的长度为26的子串,使得每个大写字母只出现一次。

题目思路:

  【模拟】

  枚举左右端点I和J,并且记录最后一个大写字母出现的位置,如果这个字母已经出现过并且最后出现的位置X在I之后,那么直接把I移动到X+1,继续做,直到I~J的长度为26

  接下来对于'?'只要从I到J依次填入没出现过的字母,其余不在I~J的随意填。

 //
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-10)
#define J 10000
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define N 50004
using namespace std;
typedef long long LL;
double anss;
LL aans;
int cas,cass;
int n,m,lll,ans;
char s[N];
int mark[];
int main()
{
#ifndef ONLINE_JUDGEW
freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
int x,y,z;
// init();
// for(scanf("%d",&cass);cass;cass--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
while(~scanf("%s",s))
// while(~scanf("%d",&n))
{
n=strlen(s);
mem(mark,-);
if(n<){puts("-1");continue;}
for(i=,j=;j<n;j++)
{
if(s[j]=='?')
{
if(j-i==)break;
continue;
}
k=s[j]-'A';
if(mark[k]!=-)
{
i=max(i,mark[k]+);
mark[k]=j;
}
else mark[k]=j;
if(j-i==)break;
}
if(j==n || j-i<)puts("-1");
else
{
x=;
for(k=i;k<=j;k++)
{
if(s[k]=='?')
{
for(;x< && mark[x]>=i;x++);
s[k]=x+'A';mark[x]=i;
}
}
for(i=;i<n;i++)
if(s[i]=='?')s[i]='A';
puts(s);
}
}
return ;
}
/*
// //
*/

Codeforces 716B Complete the Word【模拟】 (Codeforces Round #372 (Div. 2))的更多相关文章

  1. CodeForces 716B Complete the Word

    题目链接:http://codeforces.com/problemset/problem/716/B 题目大意: 给出一个字符串,判断其是否存在一个子串(满足:包含26个英文字母且不重复,字串中有‘ ...

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

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

  3. Codeforces Round #372 (Div. 2)

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

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

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

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

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

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

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

随机推荐

  1. css(字体,文本,边距,边框,阴影,背景,渐变,多重背景,列表)

    font-family 设置字体名称 可以使用多个名称,用逗号分隔,浏览器则按照先后顺序依次使用可用字体 p { font-family:'宋体','黑体','Arial'; } font-size ...

  2. 程序从高版本降到2.0,数据集报错 TypedTableBase

    错误  命名空间“System.Data”中不存在类型或命名空间名称“TypedTableBase”(是缺少程序集引用吗?) 解决: 该错误出现在自动生成的XXX.Designer.cs里. .NET ...

  3. 对xml操作

    已知有一个XML文件(bookshop.xml)如下: <?xml version="1.0" encoding="gb2312" ?> <b ...

  4. VisualStudio2013内置SQLServer入门(二)--增删改查

    前一篇 http://www.cnblogs.com/qixi233/p/4766451.html 这篇是sqlserver的操作 界面比较走心哈哈哈,将就着看,主要就是下面增删改查四个btn 对于s ...

  5. Spring 创建bean的时机

    默认在启动spring容器的时候,spring容器配置文件中的类就已经创建完成对象了        在<bean>中添加属性lazy-init,默认值为false.    true  在c ...

  6. X-Plane数据交互

    要用X-Plane进行二次开发,免不了需要进行参数的传递,下面我们来看看与X-Plane进行数据交互都有哪些方式. 与FSX和Flightgear基本一样,X-Plane支持插件,自然也支持通过插件进 ...

  7. Linux 系统命令及其使用详解(大全)

    (来源: 中国系统分析员) cat cd chmod chown cp cut 1.名称:cat 使用权限:所有使用者 使用方式:cat [-AbeEnstTuv] [--help] [--versi ...

  8. Linux redhat

    挂载U盘 fdisk -l 可以列出所有的分区,包括没有挂上的分区和usb设备.我一般用这个来查找需要挂载的分区的位置,比如挂上u盘. mount /dev/sdb1 usb/

  9. mysql,left join on

    转自http://www.oschina.net/question/89964_65912 觉得很有帮助,用来学习. 即使你认为自己已对 MySQL 的 LEFT JOIN 理解深刻,但我敢打赌,这篇 ...

  10. NSNumber

    integerfloatc 在Objective-c中有int的数据类型,那为什么还要使用数字对象NSNumber?这是因为很多类(如NSArray)都要求使用对象,而int不是对象.NSNumber ...