题目:Problem - C - Codeforces

如代码,一共有七种情况,注意不要漏掉  "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的更多相关文章

  1. 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这一点 ...

  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 ...

  3. Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)

    Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...

  4. Codeforces Round #277 (Div. 2) 题解

    Codeforces Round #277 (Div. 2) A. Calculating Function time limit per test 1 second memory limit per ...

  5. Codeforces Round #372 (Div. 2) A .Crazy Computer/B. Complete the Word

    Codeforces Round #372 (Div. 2) 不知不觉自己怎么变的这么水了,几百年前做A.B的水平,现在依旧停留在A.B水平.甚至B题还不会做.难道是带着一种功利性的态度患得患失?总共 ...

  6. Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes

                                                        D. Prefixes and Suffixes You have a string s = s ...

  7. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  8. 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 ...

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. hdu 2830 Matrix Swapping II(额,,排序?)

    题意: N*M的矩阵,每个格中不是0就是1. 可以任意交换某两列.最后得到一个新矩阵. 问可以得到的最大的子矩形面积是多少(这个子矩形必须全是1). 思路: 先统计,a[i][j]记录从第i行第j列格 ...

  2. IDEA免费激活至2099年教程,亲测可用

    申明,本教程 Intellij IDEA 最新版激活教程,激活码均收集与网络,请勿商用,仅供个人学习使用,如有侵权,请联系作者删除.如条件允许,建议大家购买正版. 以下是本人免费激活到 2099 年的 ...

  3. httprunner3源码解读(3)client.py

    源码目录结构 ApiResponse 这个类没啥好说的 class ApiResponse(Response): """ 继承了requests模块中的Response类 ...

  4. 『学了就忘』Linux基础命令 — 28、别名和常用快捷键

    目录 1.别名 2.常用快捷键 1.别名 别名也是Shell中的命令. 命令的别名,就是命令的小名,主要是用于照顾管理员使用习惯的. 命令格式: # 查询系统中命令别名 [root@localhost ...

  5. Cannot find ./catalina.sh The file is absent or does not have execute permission This file is needed to run this program(问题解决)

    web项目没有打成包,直接放在了linux服务器上. 进入tomcat/bin目录,执行启动的时候出现如下错误: 解决方法: 在tomcat 的bin目录下 执行这条命令chmod +x *.sh   ...

  6. 通俗易懂的HTML全知识梳理笔记(第一部分)

    文章目录 什么是HTML 块级元素和内联元素 属性 给`a`元素添加属性 布尔属性 HTML的空白 实体引用: 在HTML中包含特殊字符 head中的元数据 meta元素 在你的站点中增加自定义的图标 ...

  7. AppGallery Connect场景化开发实战—注册订阅通知

    借助AppGallery Connect(以下简称AGC)的认证服务,云函数,短信服务等服务,当用户注册成功后,便可以在注册的手机号或者邮箱地址中收到一条应用的欢迎短信或者欢迎邮件.以便让开发者更快地 ...

  8. 在linux 环境下 安装php

    最近打算学写一个php 脚本~ 到了虚拟机环境上发现~没有环境. 只有老老实实去装一个php环境咯. 第一步 去官网下一个包 记得一定要下载tgz格式的 第二步~当然是传上虚拟机上咯~任意目录都可以. ...

  9. 菜鸡的Java笔记 comparator 比较器

    1.数组操作类: Arrays        2.两种比较器的使用: Comparable Comparator        3.实现二叉树算法            content (内容)   ...

  10. 浏览器 Proxy SwitchyOmega 插件设置代理访问内网服务器

    使用Proxy SwitchyOmega 插件通过代理 直接访问到内网网站 一.使用场景 如下图所示,如果在电脑的网络设置中开启代理,每次更换代理就需要进入这里设置改变代理.且我们可能回需求到两个网页 ...