博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CodeForces - 877B Nikita and string
阅读量:5235 次
发布时间:2019-06-14

本文共 1183 字,大约阅读时间需要 3 分钟。

Nikita and string

One day Nikita found the string containing letters "a" and "b" only.

Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b".
Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?
Input
The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".
Output
Print a single integer — the maximum possible size of beautiful string Nikita can get.
Example
Input
abba
Output
4
Input
bab
Output
2
Note
It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful.

题意:在字符串中找到一个最长的可以不连续的子串, 子串是a..b..a..;

#include
#include
#include
using namespace std;int main(){ string s; while(cin>>s) { int a=0,ab=0,aba=0; for(int i=0;i

转载于:https://www.cnblogs.com/da-mei/p/9053317.html

你可能感兴趣的文章
百度UEditor上传图片-再总结一次
查看>>
Redis集群
查看>>
uwsgi基础——服务状态
查看>>
python引入模块
查看>>
初识dubbo(一)
查看>>
没加载redis类,却可以实例化redis
查看>>
软链接mongo
查看>>
时间戳转换
查看>>
hdu 4044 树形DP 炮台打怪 (好题)
查看>>
HDU3336 - Count the string
查看>>
VS2017提醒找不到MSVCR110D.dll
查看>>
[转][Java]简单标签库简介
查看>>
20145206邹京儒 web安全基础实践
查看>>
【python 3.6】如何将list存入txt后,再读出list
查看>>
百度地图API
查看>>
Android实现静默安装与卸载
查看>>
WPF:警惕TextBox会占用过多内存
查看>>
springboot 连接池wait_timeout超时设置
查看>>
Spring @Conditional注解的使用
查看>>
修改mysql max_allowed_packet 配置
查看>>