首页 > 代码库 > 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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。