Codeforces Round #372 (Div. 2) B. Complete the Word

54 篇文章 0 订阅
B. 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.

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.


题意:在一个字符串里找到连续的26个字母,这26个字母都不相同,为完美序列,其中?可以为任意字母,如果找不到就输出-1,找到了就输出,其中完美序列里的字母必须都不相同,把?换成相应字符,其余的不在完美序列里的用随意的字母代替;

思路:水题一道,可能我几乎从来没做过字符串的题,debug一个半小时还没有知道哪里错了。。。我一开始的思路是用一个标记s记录序列的最前面,如果找到一个重复的字母str[i],就把s变为i+1。。。是的,是变成i+1,真tm智障。。。自序列的最开头可以是从字符串的0位置到len - 25位置的任何一个。。。所以应该一个for记录开头的位置,如果在26个之内有重复的直接break,重置book数组,然后从下一个字母作为子序列开头。。。就是这么水,这么简单的题,我竟然debug一个半小时。。。这种细节跟分情况的题队友Rain是大神,分情况,处理细节很细。。向他学习。。。


比赛的代码,很丑,但还是自己比赛写的。。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1e5+5;
char str[maxn];
int book[1000];
int main()
{
    while(~scanf("%s",str))
    {
        memset(book,0,sizeof(book));
        int ans = 0;
        if(strlen(str) < 26)
            {
                printf("-1\n");
                continue;
            }
        int s = 0, flag = 0;
        for(int j = 0; j <= strlen(str) - 25; j++)
        {
            s = j;
            for(int i = j; i < strlen(str); i++)
        {
            if(str[i] <= 'Z'  && str[i] >= 'A')
                book[str[i]]++;
            ans++;
            if(book[str[i]] > 1)
            {
                ans = 0;
                memset(book,0,sizeof(book));
                break;
            }
            if(ans == 26)  {flag = 1;break;}

        }
        if(flag)  break;
        }

    //    cout << s << ' ' << e << endl;
      //  cout << ans << endl;
        if(!flag) {printf("-1\n");continue;}
        for(int i = s; i < s+26; i++)
        {
            if(str[i] == '?')
            {
                for(int k = 'A'; k <= 'Z';k++)
                {
                    if(!book[k])
                    {
                        str[i] = (char)k;
                        book[k] = 1;
                        break;
                    }
                }
            }
        }
        for(int i = 0; i < strlen(str);i++)
        {
            if(str[i] == '?')
                str[i] = 'A';
        }
        printf("%s\n",str);
    }
    return 0;
}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值