complete the world

来源:互联网 发布:三箭牌汽枪铅弹淘宝 编辑:程序博客网 时间:2024/04/27 23:12
A - Complete the Word
Crawling in process...Crawling failedTime Limit:2000MS    Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
SubmitStatus

Description

Input

Output

Sample Input

Sample Output

Hint

Description

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

Sample Input

Input
ABC??FGHIJK???OPQR?TUVWXY?
Output
ABCDEFGHIJKLMNOPQRZTUVWXYS
Input
WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO
Output
-1
Input
??????????????????????????
Output
MNBVCXZLKJHGFDSAQPWOEIRUYT
Input
AABCDEFGHIJKLMNOPQRSTUVW??M
Output

-1



#include<stdio.h>


#include<string.h>




int pan(char *a);
void solve(char *a);
int main()
{
int tag=0,i;
int len;
char ch[50001];
gets(ch);
len=strlen(ch);
if(len<26)
printf("-1\n");
else{
for(i=0;ch[i]!='\0';i++)
{
if(pan(ch+i))
{
tag=1;
solve(ch);
break;
}
}
if(tag==0)
printf("-1\n");
return 0;
}
}
int pan(char *a)
{
int numj=0;
int b[130]={0};
int k=0;
int biaozhi[100]={0};
int flag=1,que=0;
int i;
for(i=0;i<26;i++)
{
if(a[i]=='\0')
return 0;
}
for(i=0;i<26;i++)
{
if(a[i]!='?')
b[a[i]]++;
else
numj++;
}
for(i=65;i<=90;i++)
{
if(b[i]==0)
{
biaozhi[k]=i;
k++;
flag=0;
que++;
}
}
k--;
if(flag)
return 1;
else
{
if(que>numj)
return 0;
else
{
for(i=0;i<26;i++)
{
if(a[i]=='?')
{
a[i]=biaozhi[k];
k--;
}
}
return 1;
}
}
}




void solve(char *a)
{
int i;
for(i=0;a[i]!='\0';i++)
if(a[i]=='?')
a[i]='A';
puts(a);
}

0 0
原创粉丝点击