首页 > 代码库 > codeforces 372 div2 Complete the Word 716B

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