Codeforces Round #754 (Div. 2) C. Dominant Character
如代码,一共有七种情况,注意不要漏掉 "accabba" , "abbacca" 两种情况;
使用find()函数可简化代码,使用方法如下
代码:
#include <iostream>
using namespace std;
typedef long long ll;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll T;
cin >> T;
while (T--)
{
ll n, ans = -1;
string s;
cin >> n >> s;
if (s.find("accabba") != s.npos)
ans = 7;
if (s.find("abbacca") != s.npos)
ans = 7;
if (s.find("acba") != s.npos)
ans = 4;
if (s.find("abca") != s.npos)
ans = 4;
if (s.find("aba") != s.npos)
ans = 3;
if (s.find("aca") != s.npos)
ans = 3;
if (s.find("aa") != s.npos)
ans = 2;
cout << ans << endl;
}
return 0;
}
Codeforces Round #754 (Div. 2) C. Dominant Character的更多相关文章
- Codeforces Round #754 (Div. 2), problem: (A) A.M. Deviation泪目 万万没想到狂wa是因为这
Problem - A - Codeforces 题目 题意很简单每次操作可以使得a1 a2 a3任意两个数分别+1 -1 求最后使得a+c-2b绝对值的最小值 BUG就是最后忽略了-2和2这一点 ...
- Codeforces Round #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)
Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...
- Codeforces Round #277 (Div. 2) 题解
Codeforces Round #277 (Div. 2) A. Calculating Function time limit per test 1 second memory limit per ...
- Codeforces Round #372 (Div. 2) A .Crazy Computer/B. Complete the Word
Codeforces Round #372 (Div. 2) 不知不觉自己怎么变的这么水了,几百年前做A.B的水平,现在依旧停留在A.B水平.甚至B题还不会做.难道是带着一种功利性的态度患得患失?总共 ...
- Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes
D. Prefixes and Suffixes You have a string s = s ...
- Codeforces Round #677 (Div. 3) 题解
Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- python语法与pycharm的基本使用
内容概要 pycharm基本使用 python注释语法 变量与常量 垃圾回收机制 数据类型 1. pycharm基本使用 pycharm安装完成后首次打开要注意: 文件路径(不要选择C盘) pytho ...
- Mac 搭建后端PHP+Go环境
准备工作 1. 安装brew命令 #很慢很慢.. ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/insta ...
- KMP算法-字符匹配
字符匹配模式-KMP算法 j直接跳到了2的位置,因为在之前的都相同. 那么就需要求如果不等了之后,j需要回跳的位置next[j] 如果tk'与tj相等,则next [j+1]=k'+1 如果tk'与t ...
- 第一天 python入门 基础 “”“Hello World”和if-elif的使用、数据类型
(1)第一个程序"""Hello World" 实现python环境打印输出:Hello World 程序: print("Hello World&q ...
- Power Platform Center of Excellence (CoE) 部署完成&主要内容说明
随着目前国内使用Power Platform的企业越来越多,而在跟客户交付项目时,客户经常想了解平台的一些基本情况: Power Platform 有多少环境,分别是谁创建和管理? Power Pla ...
- SQL Server2019数据库备份与还原脚本,数据库可批量备份
前言 最近公司服务器到期,需要进行数据迁移,而数据库属于多而繁琐,通过图形化界面一个一个备份所需时间成本很大,所以想着写一个sql脚本来执行. 开始 数据库单个备份 数据库批量备份 数据库还原 数据库 ...
- 快来使用Portainer让测试环境搭建飞起来吧
Portainer是Docker的图形化管理工具,提供状态显示面板.应用模板快速部署.容器镜像网络数据卷的基本操作(包括上传下载镜像,创建容器等操作).事件日志显示.容器控制台操作.Swarm集群和服 ...
- 【Python】批量给图片增加水印工具
背景 最近有一些图片需要增加水印,找了一圈也没看见比较好的工具,又不想用破解的PS,干脆自己做了一个GUI工具,有需要的同学自取 功能 支持水印预览 自定义水印文字内容 支持行楷和微软雅黑两种字体 支 ...
- 洛谷 P4002 - [清华集训2017]生成树计数(多项式)
题面传送门 神题. 考虑将所有连通块缩成一个点,那么所有连好边的生成树在缩点之后一定是一个 \(n\) 个点的生成树.我们记 \(d_i\) 为第 \(i\) 个连通块缩完点之后的度数 \(-1\), ...
- 洛谷 P5470 - [NOI2019] 序列(反悔贪心)
洛谷题面传送门 好几天没写题解了,写篇题解意思一下(大雾 考虑反悔贪心,首先我们考虑取出 \(a,b\) 序列中最大的 \(k\) 个数,但这样并不一定满足交集 \(\ge L\) 的限制,因此我们需 ...