Codeforces Round #604 (Div. 2) A. Beautiful String
链接:
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的更多相关文章
- Codeforces Round #604 (Div. 2) A. Beautiful String(贪心)
题目链接:https://codeforces.com/contest/1265/problem/A 题意 给出一个由 a, b, c, ? 组成的字符串,将 ? 替换为 a, b, c 中的一个字母 ...
- Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)
链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the ...
- 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 ...
- Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest
链接: https://codeforces.com/contest/1265/problem/C 题意: So the Beautiful Regional Contest (BeRC) has c ...
- 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 ...
- Codeforces Round #604 (Div. 2) E. Beautiful Mirrors 题解 组合数学
题目链接:https://codeforces.com/contest/1265/problem/E 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只 ...
- Codeforces Round #604 (Div. 2) B. Beautiful Numbers(双指针)
题目链接:https://codeforces.com/contest/1265/problem/B 题意 给出大小为 $n$ 的一个排列,问对于每个 $i(1 \le i \le n)$,原排列中是 ...
- Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest(贪心)
题目链接:https://codeforces.com/contest/1265/problem/C 题意 从大到小给出 $n$ 只队伍的过题数,要颁发 $g$ 枚金牌,$s$ 枚银牌,$b$ 枚铜牌 ...
- Codeforces Round #604 (Div. 1) - 1C - Beautiful Mirrors with queries
题意 给出排成一列的 \(n\) 个格子,你要从 \(1\) 号格子走到 \(n\) 号格子之后(相当于 \(n+1\) 号格子),一旦你走到 \(i+1\) 号格子,游戏结束. 当你在 \(i\) ...
随机推荐
- [转帖]推荐一款比 Find 快 10 倍的搜索工具 FD
推荐一款比 Find 快 10 倍的搜索工具 FD https://www.hi-linux.com/posts/15017.html 试了下 很好用呢. Posted by Mike on 2018 ...
- 【转帖】处理器的三国时代:DR公司盛气凌人,IBM转身成就微软
处理器的三国时代:DR公司盛气凌人,IBM转身成就微软 https://www.eefocus.com/mcu-dsp/360555 <处理器史话>之五 2016-04-06 15:24 ...
- C++中的强制类型转换
在C语言中,强制类型转换的方式为(Type)Expression,另外还有一种现在已经不用的旧式写法Type(Expression),这两种方式是等价的. 但是,C语言的强制类型转换方式存在一些问题: ...
- python学习-61 类
类 (在python2里) 1.属性 ---数据属性 ---函数属性 查看属性字典 class chinese: rz:'huangzhong' print(chinese.__dict__) 运行结 ...
- Python--代码1(接口测试:测试用例从数据库读取写到yaml文件中)
一. 从数据库中读取全部接口,并写入yaml文件 数据库中的数据存储格式如下图: import pymysql import os import json # from ruamel import y ...
- PAT(B) 1067 试密码(Java)
题目链接:1067 试密码 (20 point(s)) 题目描述 当你试图登录某个系统却忘了密码时,系统一般只会允许你尝试有限多次,当超出允许次数时,账号就会被锁死.本题就请你实现这个小功能. 输入格 ...
- AVR单片机教程——数字输出
从上一篇教程中我们了解到,按键与开关的输入本质上就是数字信号的读取.这一篇教程要讲的是,控制LED的原理是数字信号的输出.数字IO是单片机编程之有别于桌面编程的各项内容中最简单.最基础的. 在讲数字信 ...
- Wing-AEP平台LWM2M设备接入
实现Wing-AEP中国电信物联网开放平台,LWM2M设备接入 一.准备 接入模组:BC35-G 平台地址:https://www.ctwing.cn/ 点击右上角控制台 点击左侧栏点击产品中心 二. ...
- kali_Airmon-ng第一次渗透测试
再看了一些资料之后,决定自己整理一下进行第一次测试,测试目标,自己宿舍的WIFI.教程仅供学习参考 断开kali连接的wifi,并检查网卡状态 airmon-ng 开启无线网卡的监控模式 airmon ...
- 少儿编程|Scratch编程教程系列合集,总有一款适合你
如果觉得资源不错,友情转发,贵在分享!!! 少儿编程Scratch: 少儿编程Scratch第一讲:Scratch完美的初体验少儿编程Scratch第二讲:奇妙的接球小游戏少儿编程Scratch第三讲 ...