CF801A.Vicious Keyboard
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
托尼奥的键盘上只有两个字母:“V”和“K”。
某天,他仅用这两个字母输入了一个字符串 s。他非常喜欢子串“VK”,因此希望至多修改字符串中的一个字母(也可以不作任何修改),以使得“VK”作为子串(即一个字母“V”后面紧跟着一个字母“K”)出现的次数最多。请计算在最终字符串中,“VK”作为子串出现的最大可能次数。
输入格式
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.
第一行将包含一个字符串 s,该字符串仅由大写英文字母 “V” 和 “K” 组成,其长度不小于 1 且不大于 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
VK
输出#1
1
输入#2
VV
输出#2
1
输入#3
V
输出#3
0
输入#4
VKKKKKKKKKVVVVVVVVVK
输出#4
3
输入#5
KVKV
输出#5
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.
对于第一种情况,我们不改变任何字母。“VK”出现一次,这是它可能达到的最大出现次数。
对于第二种情况,我们可以将第二个字符从“V”改为“K”,从而得到字符串“VK”。该字符串作为子串包含一个“VK”。
对于第四种情况,我们可以将第四个字符从“K”改为“V”,从而得到字符串“VKKVKKKKKKVVVVVVVVVK”。该字符串作为子串包含三个“VK”。我们可以验证:不存在其他操作能得到严格更多的“VK”出现次数。
输入解题思路,AI测评打分。不知道怎么写?