A. Vicious Keyboard codeforce
来源:互联网 发布:微信会员卡源码下载 编辑:程序博客网 时间:2024/05/18 11:33
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.
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int main(){char s[105];int vis[105];while(~scanf("%s",s)){ memset(vis,0,sizeof(vis));int l=strlen(s);if(l==1)cout<<"0"<<endl;else if(l==2){if(s[0]=='K'&&s[1]=='V')cout<<"0"<<endl;elsecout<<"1"<<endl;}else if(l==3){cout<<"1"<<endl;}else{int num=0;for(int i=0;i<l-1;i++){if(s[i]=='V'&&s[i+1]=='K'){num++; vis[i]=1; vis[i+1]=1;}}for(int i=0;i<l-1;i++){if((!vis[i]&&!vis[i+1]&&s[i]=='V'&&s[i+1]=='V')||(!vis[i]&&!vis[i+1]&&s[i]=='K'&&s[i+1]=='K')){num++;break;}}cout<<num<<endl;}}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
- HTTP权威指南读书笔记三:HTTP报文
- Python中垃圾回收机制的理解
- Machine learning
- my preaentation
- SVN恢复某个文件到特点版本
- A. Vicious Keyboard codeforce
- 文件和目录操作
- TP框架学习笔记第三天
- 每天一个Linux命令(59):ssh
- 贪心算法
- centos7获取ip两种方式
- 程序猿的骄傲,以及骄傲背后真实的原因。
- class--review python
- 静态库和动态库制作