A. Vicious Keyboard Codeforce
来源:互联网 发布:移动网络电视好吗? 编辑:程序博客网 时间:2024/05/18 09:29
Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string s with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times "VK" can appear as a substring (i. e. a letter "K" right after a letter "V") in the resulting string.
The first line will contain a string s consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100.
Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character.
VK
1
VV
1
V
0
VKKKKKKKKKVVVVVVVVVK
3
KVKV
1
For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.
For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.
For the fourth case, we can change the fourth character from a "K" to a "V". This will give us the string "VKKVKKKKKKVVVVVVVVVK". This has three occurrences of the string "VK" as a substring. We can check no other moves can give us strictly more occurrences.
数据不大,直接暴力
Ac code:
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <vector>#include <queue>#include <stack>#include <string>#include <map>using namespace std;#define LL long long#define INF 0x3f3f3f3f#define fi first#define se second#define eps 1const int maxn=200000+500;int main() { char s[105]; int vis[105];while(~scanf("%s",s)){memset(vis,0,sizeof vis);int cnt=0;int len=strlen(s);for(int i=0;i<len-1;i++){if(s[i]=='V'&&s[i+1]=='K'){cnt++;vis[i]=vis[i+1]=1;i++;}}for(int i=0;i<len-1;i++){if((s[i]=='V'||s[i+1]=='K')&&vis[i]==0&&vis[i+1]==0){cnt++;break;}}printf("%d\n",cnt );}return 0;}
- A. Vicious Keyboard codeforce
- A. Vicious Keyboard Codeforce
- A. Vicious Keyboard
- A. Vicious Keyboard
- A. Vicious Keyboard
- Codeforces 801A Vicious Keyboard
- CodeForces 801A Vicious Keyboard
- codeforces 801A Vicious Keyboard
- CodeForces 801A Vicious Keyboard 模拟
- Codeforces Round #409 (Div. 2) A. Vicious Keyboard
- CF#801 A. Vicious Keyboard(字符串,水题)
- Codeforces801A Vicious Keyboard
- Codeforces801A Vicious Keyboard
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) A. Vicious Keyboard
- 0519 G2n#W2B-B Vicious Keyboard
- CF Vicious Keyboard 构造水题
- CF-Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2)-A-Vicious Keyboard
- Codeforce A
- ATF实现原理
- 什么是阿里云轻量应用服务器?它有什么优点?值得购买吗?
- 关于redis的一些简单理解和应用
- UVA 11478 Halum 二分+差分约束+SPFA
- Spring Boot结合cxf发布WebService接口jar包冲突的问题
- A. Vicious Keyboard Codeforce
- eclipse和myeclipse取消所有断点
- MySQL查看和设置会话系统变量的方法
- jsp页面中引入js路径的问题
- imagesloaded源码分析
- NOI2015 软件包管理器
- springboot中使用定时任务,异步调用,自定义配置参数(八)
- 每日一练-10
- 第五章