CF716B Complete the Word 题解

分析

首先观察数据范围是 \(50000\),可以考虑 \(O(n)\) 暴力。

在字符串中枚举子串开始的位置 \(i\),然后再枚举 \(i\) 到 \(i+25\),开个桶统计每个大写字母出现的次数,如果大于 \(1\) 就直接 break。统计完之后剩下的就都是问号了,可以随便填,所以这个子串是一定合法的。用 \(ans\) 来截取这一段合法子串,\(st\) 记录 \(ans\) 的起始位置,方便输出。如果所有子串都枚举完没有合法的,输出 \(-1\) 即可。

输出时没到子串 \(ans\) 时输出原串,问号随便输出。枚举到 \(st\) 时就输出 \(ans\),问号处缺啥填啥。

代码

代码过长,参考为主,不喜勿喷

#include <bits/stdc++.h>
using namespace std;
namespace Raiden
{
int t[30];
signed work()
{
string s, ans;
int st;
cin >> s;
if (s.size() < 26)
cout << -1 << endl, return 0;
bool flag = 1;
for (int i = 0; i <= s.size() - 26; i++)
{
flag = 1;
memset(t, 0, sizeof(t));
for (int j = i; j < i + 26; j++)
{
if (s[j] != '?')
{
if (t[s[j] - 'A'] > 0)
flag = 0, break;
t[s[j] - 'A']++;
}
}
if (flag)
{
ans = s.substr(i, 26);
st = i;
break;
}
}
if (!flag)
cout << -1 << endl, return 0;
for (int i = 0; i < s.size(); i++)
{
if (i == st)
{
for (auto it : ans)
{
if (it == '?')
{
for (int i = 0; i < 26; i++)
if (t[i] == 0)
{
cout << char(i + 'A');
t[i]++;
break;
}
}
else
cout << it;
}
i = st + 25;
}
else
{
if (s[i] == '?')
cout << 'A';
else
cout << s[i];
}
}
return 0;
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
return Raiden::work();
}

CF716B Complete the Word 题解的更多相关文章

  1. Codeforces 716B Complete the Word【模拟】 (Codeforces Round #372 (Div. 2))

    B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  2. B. Complete the Word(Codeforces Round #372 (Div. 2)) 尺取大法

    B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  3. Codeforces Round #372 (Div. 2) A .Crazy Computer/B. Complete the Word

    Codeforces Round #372 (Div. 2) 不知不觉自己怎么变的这么水了,几百年前做A.B的水平,现在依旧停留在A.B水平.甚至B题还不会做.难道是带着一种功利性的态度患得患失?总共 ...

  4. codeforces 372 Complete the Word(双指针)

    codeforces 372 Complete the Word(双指针) 题链 题意:给出一个字符串,其中'?'代表这个字符是可变的,要求一个连续的26位长的串,其中每个字母都只出现一次 #incl ...

  5. Complete the Word CodeForces - 716B

    ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists asubstring  ...

  6. Complete the Word

    ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring ...

  7. CodeForces 716B Complete the Word

    题目链接:http://codeforces.com/problemset/problem/716/B 题目大意: 给出一个字符串,判断其是否存在一个子串(满足:包含26个英文字母且不重复,字串中有‘ ...

  8. Codeforces Round #372 +#373 部分题解

    用了两场比赛上Div 1感觉自己好腊鸡的说...以下是这两场比赛的部分题解(不得不说有个黄学长来抱大腿还是非常爽的) Round #372 : Div 2 A:Crazy Computer 题意:给定 ...

  9. CodeForces 715B Complete The Graph 特殊的dijkstra

    Complete The Graph 题解: 比较特殊的dij的题目. dis[x][y] 代表的是用了x条特殊边, y点的距离是多少. 然后我们通过dij更新dis数组. 然后在跑的时候,把特殊边都 ...

  10. Codeforces Round #372 (Div. 2) A B C 水 暴力/模拟 构造

    A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

随机推荐

  1. 【CMake系列】09-cmake install 一般文件 文件夹 代码文件

    上一节,我们学习了项目构建后.目标的安装,本节学习的内容是 对于一般文件,文件夹以及源代码的安装 本节的文件依然使用 file(WRITE xxx.xx) 来创建,不依赖额外的文件 本专栏的实践代码全 ...

  2. NetCore消息管道 Middleware

    中间件定义 /// <summary> /// 自定义中间件1 /// </summary> public class MyMiddleware : IMiddleware { ...

  3. How-many

    #include <bits/stdc++.h> #include <termio.h> #include <unistd.h> typedef long long ...

  4. HarmonyOS NEXT未成年人模式无缝联动所有应用,过滤非适龄内容

    背景 随着消费电子产品和移动互联网的普及,未成年人互联网普及率96.8%,超过80%的未成年人都拥有自己的上网设备,而如何引导孩子正确上网一直是家长们的担忧.市场上很多电子设备.系统推出了一些未成年人 ...

  5. python pyqt6 QPushButton 设定快捷键

      import os import sys from PyQt6.QtWidgets import QPushButton from PyQt6.QtGui import QIcon from Py ...

  6. 淘宝订单信息获取接口,淘宝开放平台R2权限,淘宝开放平台订单获取接口

    目前淘宝开放平台是关闭了订单权限申请的,有这方便的需求的人,除非是天猫用户才能申请(天猫用户申请到只能给自己天猫店授权),否则是申请不到这个订单接口了,如果有这方面需要的人可以联系我,站内信留下QQ或 ...

  7. 【YashanDB知识库】数据库使用shutdown immediate无响应导致coredump

    [标题]数据库使用shutdown immediate无响应导致coredump [问题分类]数据库维护 [关键词]YashanDB, shutdown immediate, coredump [问题 ...

  8. 【Azure Developer】上手 The Best AI Code "Cursor" : 仅仅7次对话,制作个人页面原型,效果让人惊叹!

    AI Code 时代早已开启,自己才行动.上手一试,让人惊叹.借助这感叹的情绪,把今天操作Cursor的步骤记录下来,也分享给大家. 推荐大家上手一试,让你改变! 准备阶段 下载 Cursor(htt ...

  9. linux 环境中cat命令进行关键字搜索

    在linux环境中通过关键字搜索文件里面的内容 1.显示文件里匹配关键字那行以及上下50行 cat 文件名 | grep -C 50 '关键字' 2.显示关键字及前50行 cat 文件名 | grep ...

  10. elementUI 时间线居左显示

    elementUI 时间线居左显示 一.vue + elementUI 实现时间线 Timellne 中时间戳居左显示 二.效果图 三.实现方法 关键代码: <el-timeline> & ...