codeforces #442 B
来源:互联网 发布:手机屏幕动物软件 编辑:程序博客网 时间:2024/05/01 20:48
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?
The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".
Print a single integer — the maximum possible size of beautiful string Nikita can get.
abba
4
bab
2
It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful.
自己代码不忍直视 贴一个巨巨的 代码好强
#include<stdio.h>#include<iostream>#include<string>#include<math.h>using namespace std;int max(int a,int b){return a>b?a:b;}int main(){ std::ios::sync_with_stdio(false); string s; cin>>s; int n=s.length(),i; int a=0,aba=0,ab=0; for(i=0;i<n;i++) { if(s[i]=='a') aba++,a++; //记录总长度最长 和 a 的长度 if(s[i]=='b')ab++; //记录 aaaa这样的最长 还是 aaaaabbbb这种类型的 最长的长度 aba=max(aba,ab); ab=max(ab,a); } cout<<aba; return 0;}
- CodeForces 442B
- codeforces #442 B
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- Codeforces 442B Andrey and Problem(贪心)
- Codeforces Round #442 (Div. 2) A B
- Codeforces Round #442 (Div. 2) B
- CodeForces 626B CodeForces 626B【暴力】
- CodeForces 841B (B) 博弈
- codeforces 134B
- codeforces#98 b
- codeforces 105 div2 B
- Codeforces 166B - Polygons
- codeforces B. Coins
- codeforces----193B Xor
- codeforces----208B Solitaire
- 腾讯云 centos7 配置服务器所需要知道的
- 面试Java web,有关于hibernate一般都问什么问题?
- 自定义浏览器协议,实现web页面调用本地程序
- EA&UML日拱一卒-状态图::状态机
- Test 2017.10.24
- codeforces #442 B
- 基本图像变换:线性变换,仿射变换,投影变换
- 求最大和最小值(SDIBTOJ 2001)
- 【软件安装】Windows下Anaconda安装+tensorflow安装
- Sublime text3注册码
- 《代码整洁之道》
- bootstrap datetimepicker日期插件超详细使用方法介绍
- Mysql数据库的优化
- HDU-1864 01背包