CodeForces 716B Complete the Word 统计
来源:互联网 发布:电脑怎么改网络ip地址 编辑:程序博客网 时间:2024/06/03 14:47
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 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.
Sample Input
ABC??FGHIJK???OPQR?TUVWXY?
ABCDEFGHIJKLMNOPQRZTUVWXYS
WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO
-1
??????????????????????????
MNBVCXZLKJHGFDSAQPWOEIRUYT
AABCDEFGHIJKLMNOPQRSTUVW??M
-1
Hint
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.
#include <iostream> #include <cstdio>#include <cstdlib>#include <cmath>#include <algorithm>#include <climits>#include <cstring>#include <string>#include <set>#include <map>#include <queue>#include <stack>#include <vector>#include <list>#define rep(i,m,n) for(i=m;i<=n;i++)#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)const int inf_int = 2e9;const long long inf_ll = 2e18;#define inf_add 0x3f3f3f3f#define mod 1000000007#define vi vector<int>#define pb push_back#define mp make_pair#define fi first#define se second#define pi acos(-1.0)#define pii pair<int,int>#define Lson L, mid, rt<<1#define Rson mid+1, R, rt<<1|1const int maxn=5e2+10;using namespace std;typedef long long ll;typedef unsigned long long ull; inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,rx=getchar();return ra*fh;}//#pragma comment(linker, "/STACK:102400000,102400000")ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}char str[50005];int flag[30];int main(){int i,j,ct;cin >> str;int len = strlen(str);for(i=0;i<=len-26;i++){ct = 0;memset(flag,0,sizeof(flag));for(j=i;j<=i+25;j++){if(str[j]!='?'){if(flag[str[j]-'A']>=1)break;flag[str[j]-'A'] ++;ct ++ ;}} if(j==i+26){for(int k=0;k<26;k++){if(flag[k]==0){for(int k1=i;k1<=i+25;k1++){if(str[k1]=='?'){str[k1] = 'A'+k;break;}} }}for(int k1=0;k1<len;k1++){if(str[k1]=='?')str[k1] = 'A'; } cout << str <<endl;return 0;}}cout << "-1" <<endl;return 0;}
- CodeForces 716B Complete the Word 统计
- Codeforces 716B B. Complete the Word
- Codeforces-716B-Complete the Word
- Codeforces 716B Complete the Word
- codeforces-716B - Complete the Word
- Codeforces 716B Complete the Word
- Codeforces 716 B Complete the Word【模拟】
- 【CodeForces】716B - Complete the Word(暴力)
- CodeForces-716B. Complete the Word(模拟)
- Codeforces B. Complete the Word By Assassin
- B. Complete the Word
- Codeforces 716B Complete the Word【模拟】 (Codeforces Round #372 (Div. 2))
- 【Codeforces Round #372 (Div. 2)】Codeforces 716B Complete the Word
- 【20.73%】【CF 716B】Complete the Word
- Coderforces 716B Complete the Word
- codefroces 716B.Complete the Word
- Codeforces Round #372 (Div. 2) B. Complete the Word
- Codeforces Round #372 (Div. 2) B. Complete the Word
- 数据库实验三 嵌套查询和视图操作
- 数据库删除带外键的字段
- C++ STL
- 区块链这台永不休止的信任机器,一文看清它的成长逻辑
- SQLite数据库损坏与修复
- CodeForces 716B Complete the Word 统计
- java集合框架的理解
- 接触一下逆向-,-
- jQuery日记(1)--jQuery基础和选择器
- 比特币和区块链全生态:从只会入门挖矿到玩法样样精通
- 常见的语音交互平台的简介和比较
- 1142
- 二维数组行列互调
- PL/SQL 数据库访问的相关技术(2)游标 、异常、存储过程、函数、包、触发器