complete the world
来源:互联网 发布:三箭牌汽枪铅弹淘宝 编辑:程序博客网 时间:2024/04/27 23:12
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
ABC??FGHIJK???OPQR?TUVWXY?
ABCDEFGHIJKLMNOPQRZTUVWXYS
WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO
-1
??????????????????????????
MNBVCXZLKJHGFDSAQPWOEIRUYT
AABCDEFGHIJKLMNOPQRSTUVW??M
-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);
}
- complete the world
- ECL - The Complete Guide
- C++: The Complete Reference
- The Beatles - Complete Scores
- Linux: The Complete Reference
- J2ME: the complete reference
- Struts: The Complete Reference
- SQL: The Complete Reference
- SQL: The Complete Reference
- Oracle9i: The Complete Reference
- Perl: The Complete Reference
- Ajax: The Complete Reference
- Ubuntu: The Complete Reference
- Complete Building the Houses
- Maven: The Complete Reference
- hdu1121 Complete the Sequence
- B. Complete the Word
- complete the word
- 【计蒜客简单题】批量替换字符串
- 3.20
- Linux内核通知链(Notifier)
- jsp页面取整数 和Java页面取整数
- Paint及Canvas的简单应用
- complete the world
- java 发送邮件
- Unity学习笔记—入门
- Linux与Android 多点触摸协议
- Spring Data JPA 指南——整理自官方参考文档
- 基于TCP协议的网络编程:
- ehcache缓存
- Window对象详解
- 我碰到关于蓝牙的技术问题