题目链接:https://codeforces.com/contest/1265/problem/A

题意

给出一个由 a, b, c, ? 组成的字符串,将 ? 替换为 a, b, c 中的一个字母,问能否字符串中所有相邻字母都不同。

题解

除非一开始字符串就不合法,否则一定可以构造出合法的字符串,因为共有三个字母可选,而替换时最多需要判断前后两个位置。

代码

#include <bits/stdc++.h>
using namespace std; void solve() {
string s; cin >> s;
for (int i = 1; i < s.size(); i++)
if (islower(s[i]) and s[i] == s[i - 1]) {
cout << -1 << "\n";
return;
}
for (int i = 0; i < s.size(); i++)
if (s[i] == '?')
for (char c : {'a', 'b', 'c'})
if (i == 0) {
if (c != s[i + 1])
s[i] = c;
} else if (i == s.size() - 1) {
if (c != s[i - 1])
s[i] = c;
} else {
if (c != s[i - 1] and c != s[i + 1])
s[i] = c;
}
cout << s << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}

Codeforces Round #604 (Div. 2) A. Beautiful String(贪心)的更多相关文章

  1. Codeforces Round #604 (Div. 2) A. Beautiful String

    链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecu ...

  2. Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)

    链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the ...

  3. Codeforces Round #604 (Div. 2) E. Beautiful Mirrors

    链接: https://codeforces.com/contest/1265/problem/E 题意: Creatnx has n mirrors, numbered from 1 to n. E ...

  4. Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest

    链接: https://codeforces.com/contest/1265/problem/C 题意: So the Beautiful Regional Contest (BeRC) has c ...

  5. Codeforces Round #604 (Div. 2) B. Beautiful Numbers

    链接: https://codeforces.com/contest/1265/problem/B 题意: You are given a permutation p=[p1,p2,-,pn] of ...

  6. Codeforces Round #604 (Div. 2) E. Beautiful Mirrors 题解 组合数学

    题目链接:https://codeforces.com/contest/1265/problem/E 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只 ...

  7. Codeforces Round #604 (Div. 2) B. Beautiful Numbers(双指针)

    题目链接:https://codeforces.com/contest/1265/problem/B 题意 给出大小为 $n$ 的一个排列,问对于每个 $i(1 \le i \le n)$,原排列中是 ...

  8. Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest(贪心)

    题目链接:https://codeforces.com/contest/1265/problem/C 题意 从大到小给出 $n$ 只队伍的过题数,要颁发 $g$ 枚金牌,$s$ 枚银牌,$b$ 枚铜牌 ...

  9. Codeforces Round #604 (Div. 1) - 1C - Beautiful Mirrors with queries

    题意 给出排成一列的 \(n\) 个格子,你要从 \(1\) 号格子走到 \(n\) 号格子之后(相当于 \(n+1\) 号格子),一旦你走到 \(i+1\) 号格子,游戏结束. 当你在 \(i\) ...

随机推荐

  1. git的基础知识

    git 分布式版本控制工具 具备的功能 协同开发 多人并行不悖修改服务器端的同一个文件 数据备份 不仅保持目录和文件当前状态,还能保存每一个提交的历史版本 版本管理 保存每一个版本的文件信息的时候做到 ...

  2. 【JavaWeb】XML 文件

    XML 文件 简介 XML 是可拓展的标记性语言. XML 的主要作用: 用来保存数据,且这些数据具有自我描述性: 作为项目或模块的配置文件: 作为网络数据传输的格式,但是现在以 JSON 格式为主. ...

  3. 【C++】《C++ Primer 》第五章

    第五章 语句 一.简单语句 表达式语句:一个表达式末尾加上分号,就变成了表达式语句. 空语句:只有一个单独的分号,记得注释说明提高代码可读性. 复合语句(块):用花括号 {}包裹起来的语句和声明的序列 ...

  4. 18.java设计模式之中介者模式

    基本需求 智能家庭包括各种设备,闹钟.咖啡机.电视机.窗帘等 要看电视时,各个设备可以协同工作,自动完成看电视的准备工作,比如流程为:闹铃响起->咖啡机开始做咖啡->窗帘自动落下-> ...

  5. Java 安全之Weblogic 2018-2628&2018-2893分析

    Java 安全之Weblogic 2018-2628&2018-2893分析 0x00 前言 续上一个weblogic T3协议的反序列化漏洞接着分析该补丁的绕过方式,根据weblogic的补 ...

  6. 【ORA】ORA-01033,ORA-09968,ORA-01102

    [oracle@oracle ~]$ imp xxxx/user file=/usr/local/src/666.dmp full=y buffer=40960000 Import: Release ...

  7. CTFshow-萌新赛杂项_劝退警告

    下载附件 https://www.lanzous.com/i9wocah 下载后得到一个劝退警告.zip 解压得到一张gif图片 使用binwalk分析发现包含zip 于是拿到了一个压缩包 打开后发现 ...

  8. wmic 操作文件的datafile

    wmic datafile /?动词有ASSOC,CALL,CREATE,DELETE,GET,LIST 这几个 命令:wmic datafile where "filename='dsc0 ...

  9. 在Ubuntu18.04下编译出ffmpeg(支持推流H265成rtmp)

    Ubuntu18.04下编译libx264.libx265.libfdk_aac和ffmpeg 一.编译x264库 二.编译fdk-aac库 三.编译x265库 四.编译FFmpeg源码 五.设置环境 ...

  10. Py数据类型—列表,字典,元组

    列表:数据类型list. 写法li=[1,12,9,"sdsad",["ad","dd"] ].用中括号括起来,用逗号分割每个元素列表中元素 ...