A. Vicious Keyboard
来源:互联网 发布:阿里云造价 编辑:程序博客网 时间:2024/05/18 09:06
A. Vicious Keyboard
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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.
Input
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
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.
Examples
input
VK
output
1
input
VV
output
1
input
V
output
0
input
VKKKKKKKKKVVVVVVVVVK
output
3
input
KVKV
output
1
Note
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<cstring>#include<cstdio>#include<algorithm>#include<iomanip>#include<string>using namespace std;#define INF 9999999int main(){ string str; while (cin >> str) { int ans = 0;int flag = 0; for (int i = 0;i < str.length() - 1;i++) { if (str.at(i) == 'V') { if (str.at(i + 1) == 'K') { ans++; } } } str = str+" "; string temp = "ABCD"; str = temp + str; //cout << str << endl; for (int i = 0;i < str.length()-2;i++) { if (str.at(i) == 'V'&&str.at(i + 1) == 'V'&&str.at(i + 2) != 'K') { flag = 1; break; } else if (str.at(i) != 'V'&&str.at(i + 1) == 'K'&&str.at(i + 2) == 'K') { flag = 1; break; } } cout << ans + flag << endl; } return 0;}
- A. Vicious Keyboard
- A. Vicious Keyboard codeforce
- A. Vicious Keyboard
- A. Vicious Keyboard
- A. Vicious Keyboard Codeforce
- 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
- A. Keyboard
- 漫谈程序员系列:请区别对待女程序员
- Vim编辑器”入门1--总结自实验楼
- linux查看php安装了哪些扩展
- 学习淘淘商城第五十四课(为何引入ActiveMQ)
- 有关于正则表达式(初步了解)
- A. Vicious Keyboard
- 谁能赢呢?
- react demo9 (组件属性验证propTypes)
- Oracle 中的 to_date(), to_char(), to_number() 用途用法
- [知识点滴]HTML5语义化总结
- 携程日处理20亿数据,实时用户行为服务系统架构实践
- Android 音频系统:从 AudioTrack 到 AudioFlinger
- hdu1241
- trafficserver的DNS初始化源码分析一