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

时间:2023-01-17 11:47:19

链接:

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 &num;604 &lpar;Div&period; 2&rpar; A&period; Beautiful String(贪心)

    题目链接:https://codeforces.com/contest/1265/problem/A 题意 给出一个由 a, b, c, ? 组成的字符串,将 ? 替换为 a, b, c 中的一个字母 ...

  2. Codeforces Round &num;604 &lpar;Div&period; 2&rpar; D&period; Beautiful Sequence&lpar;构造&rpar;

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

  3. Codeforces Round &num;604 &lpar;Div&period; 2&rpar; E&period; Beautiful Mirrors

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

  4. Codeforces Round &num;604 &lpar;Div&period; 2&rpar; C&period; Beautiful Regional Contest

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

  5. Codeforces Round &num;604 &lpar;Div&period; 2&rpar; B&period; Beautiful Numbers

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

  6. Codeforces Round &num;604 &lpar;Div&period; 2&rpar; E&period; Beautiful Mirrors 题解 组合数学

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

  7. Codeforces Round &num;604 &lpar;Div&period; 2&rpar; B&period; Beautiful Numbers(双指针)

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

  8. Codeforces Round &num;604 &lpar;Div&period; 2&rpar; C&period; Beautiful Regional Contest(贪心)

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

  9. Codeforces Round &num;604 &lpar;Div&period; 1&rpar; - 1C - Beautiful Mirrors with queries

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

随机推荐

  1. React Native图片控件的使用

    首先定义组件 import { AppRegistry, StyleSheet, Text, View, Image,} from 'react-native'; 然后将render返回中的模版增加I ...

  2. plain framework 1 网络流 缓存数据详解

    网络流是什么?为什么网络流中需要存在缓存数据?为什么PF中要采用缓存网络数据的机制?带着这几个疑问,让我们好好详细的了解一下在网络数据交互中我们容易忽视以及薄弱的一块.该部分为PF现有的网络流模型,但 ...

  3. 学习Java,还需要学好哪些知识

    很多人认为学好一门程序语言就需要学好逻辑,其实这对于很多人而言是对的,但是真的对于需要写程序的学员来说,只有逻辑好其实是不够的,如果你能具备以下几项能够为你在程序编译中大大提高工作效率.现在昆明jav ...

  4. 【Cocos2d-Js基础教学 入门目录】

    本教程视地址频在: 九秒课堂 完全免费 从接触Cocos2dx-Js以来,它的绽放的绚丽让我无法不对它喜欢.我觉得Js在不断带给我们惊喜:在开发过程中,会大大提升我们对原型开发的利用率,使用Js语言做 ...

  5. PostgreSQL Insight Monitor pgstat

    PostgreSQL Insight Monitor  pgstat pgstat 是一个连接到数据库并获取数据库的活动状态的命令行工具. PostgreSQL有许多状态: archiver for ...

  6. HDU 2126 Buy the souvenirs (01背包,输出方案数)

    题意:给出t组数据 每组数据给出n和m,n代表商品个数,m代表你所拥有的钱,然后给出n个商品的价值 问你所能买到的最大件数,和对应的方案数.思路: 如果将物品的价格看做容量,将它的件数1看做价值的话, ...

  7. 讲解HTML服务器推送相关技术知识&lpar;转&rpar;

    1. 为什么需要服务器推送? 最大的优点:实时 健康知识平台重庆男科医院 重庆妇科医院适用场景:实时股票价格.商品价格.实时新闻.Twitter/weibo timeline.基于浏览器的聊天系统 2 ...

  8. Codeforces Round &num;333 &lpar;Div&period; 2&rpar; B&period; Approximating a Constant Range st 二分

    B. Approximating a Constant Range Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com ...

  9. Android架构分析之Android消息处理机制(二)

    作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz Android版本号:4.4.2 在上一篇文章中我们看了一个使用Handler处理Message消息的样例,本文我们 ...

  10. 基于Bootstrap实现下图所示效果的页面,一个白底的带有两个菜单项、一个下拉菜单和一个登录表单的基本导航条

    <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="utf-8& ...