链接:

https://codeforces.com/contest/1265/problem/A

题意:

A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.

Ahcl wants to construct a beautiful string. He has a string s, consisting of only characters 'a', 'b', 'c' and '?'. Ahcl needs to replace each character '?' with one of the three characters 'a', 'b' or 'c', such that the resulting string is beautiful. Please help him!

More formally, after replacing all characters '?', the condition si≠si+1 should be satisfied for all 1≤i≤|s|−1, where |s| is the length of the string s.

思路:

直接暴力枚举,判断一遍

代码:

#include<bits/stdc++.h>
using namespace std; string s; int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while(t--)
{
cin >> s;
bool flag = true;
for (int i = 0;i < s.length();i++)
{
if (s[i] == '?')
{
int t = -1;
for (int j = 0;j < 3;j++)
{
if ((i-1 < 0 || s[i-1] != (char)('a'+j)) && (i+1 >= s.length() || s[i+1] != (char)('a'+j)))
{
t = j;
break;
}
}
s[i] = (char)('a'+t);
}
}
for (int i = 1;i < s.length();i++)
{
if (s[i] == s[i-1])
flag = false;
}
cout << (flag ? s : "-1") << endl;
} return 0;
}

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, b, c, ? 组成的字符串,将 ? 替换为 a, b, c 中的一个字母 ...

  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. 09 Servlet相关知识点---学习笔记

    1.概念:运行在服务器端的小程序 Servlet就是一个接口,定义了Java类被浏览器访问到(tomcat识别)的规则.将来我们自定义一个类,实现Servlet接口,复写方法. 2.快速入门:(1)创 ...

  2. ContainsExtensions不分区大小写

    public static class ContainsExtensions { public static bool Contains(this string source, string valu ...

  3. c++基础(四)—— 泛型算法

    1.find(first, last, value) 头文件:algorithm 参数:前两个参数是“表示元素范围的迭代器”,第三个是一个值 说明:find 将范围中进行寻找.搜索失败:如果范围中无匹 ...

  4. 【翻译】在GitHub上通过星级评估排名前10的最受欢迎的开源Delphi项目

    GitHub上有相当多的Delphi开源项目可以为你节省一些时间.我在GitHub上搜索了Delphi,然后按最主要的项目进行排序,并列出了前十名单.这里有一些非常好的东西,包括Awesome Del ...

  5. windows10环境下的RabbitMQ使用_笔记

    使用默认账号:guest/guest登录http://localhost:15672/#/进去,添加一个新用户(Administrator权限),并设置其Permission 新建两个控制台程序 安装 ...

  6. memcpy 速度测试

    1. 小米8代i5    3840X2160X4   7.77ms      即34Gbps

  7. flutter 动画 practice

    import 'package:flutter/material.dart'; import 'dart:io'; import 'dart:async'; main() => runApp(M ...

  8. SQL注入绕过技巧

    1.绕过空格(注释符/* */,%a0): 两个空格代替一个空格,用Tab代替空格,%a0=空格: % % %0a %0b %0c %0d %a0 %00 /**/ /*!*/ 最基本的绕过方法,用注 ...

  9. Keepalived简单理解

    Keepalived Keepalived是一个基于VRRP协议来实现的LVS服务高可用方案,可以利用其来避免单点故障.一个LVS服务会有2台服务器运行Keepalived,一台为主服务器(MASTE ...

  10. 织梦dedecms是什么?

    织梦dedecms是什么?DedeCms是织梦内容管理系统(DedeCms)的简称, 以简单.实用.开源而闻名,是国内最知名的PHP开源网站管理系统,也是使用用户最多的PHP类CMS系统; DedeC ...