codeforces 372 div2 Complete the Word 716B

Posted fzfn5049

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了codeforces 372 div2 Complete the Word 716B相关的知识,希望对你有一定的参考价值。

大概有三次的CF没有补了,国庆后,慢慢开始

这个题目,异常之暴力,我自己都觉得代码写的不优美....但是实在只是一个暴力,随便写写就好

遍历数组,每一位枚举26个,判断问号数量或者重复数量....

#include <stdio.h>
#include <string>
#include <iostream>
#include <string.h>
using namespace std;

char s[] = "QWERTYUIOPLKJHGFDSAZXCVBNM";

int main()
{
	char s1[50006];
	scanf("%s", s1);
	int num[30];
	int len = strlen(s1);
	int flag;
	int sum = 0;
	int sum1 = 0;

	if(len < 26)
		printf("-1\n");

	else
	{
		int i, j;
		for(i = 0; i < len - 26 + 1; i++)
		{
			memset(num, 0, sizeof(num));
			flag = 0;
			 sum = 0;
			 sum1 = 0;
			for(j = i; j <= i + 25; j++)
			{
				//printf("!!!!\n");
				if(s1[j] == ‘?‘)
				{
					sum1++;
					continue;
				}
				
				else if(num[s1[j] - ‘A‘] == 0)
				{
					sum++;
					num[s1[j] - ‘A‘] = 1;
					continue;
				}
				
				else if(num[s1[j] - ‘A‘] == 1)
					break;
			}

			if(sum + sum1 == 26)
			{
				flag = 1;
				if(sum1 == 0)
					break;
				else
				{
					for(j = i; j <= i + 25; j++)
					{
						if(s1[j] == ‘?‘)
						{
							for(int k = 0; k < 26; k++)
							{
								if(num[k + ‘A‘ - ‘A‘] == 0)
								{
									s1[j] = k + ‘A‘;
									num[k + ‘A‘ - ‘A‘] = 1;
									break;
								}
							}
						}
					}
					break;
				}
			}
		}

		//printf("%d\n", sum);
		if(flag == 0)
			printf("-1\n");
		
		else
		{
			memset(num, 0, sizeof(num));
			for(i = 0; i < len; i++)
				if(s1[i] == ‘?‘)
				{
					for(int k = 0; k < 26; k++)
					{
						if(num[k + ‘A‘ - ‘A‘] == 0)
						{
							s1[i] = k + ‘A‘;
							num[k + ‘A‘ - ‘A‘] = 1;
							break;
						}
					}
				}
			for(i = 0; i < len; i++)
				if(s1[i] == ‘?‘)
					s1[i] = ‘A‘;
			printf("%s\n", s1);
		}
	}
}

  

以上是关于codeforces 372 div2 Complete the Word 716B的主要内容,如果未能解决你的问题,请参考以下文章

[CodeForces 372A] Counting Kangaroos is Fun

Codeforces Round #372 (Div. 2) B

Codeforces Round #372 (Div. 2) A

Codeforces 372B Counting Rectangles is Fun

7.26-Codeforces Round #372 (Div. 2)

Codeforces 372B Counting Rectangles is Fun:dp套dp