您的位置:首页 > 其它

0519 G2n#W2B-B Vicious Keyboard

2017-05-20 13:37 267 查看
摘要:判断给定最多可修改一个字符后的字符串中 特殊子串的数量。 

原题目:CodeForces
- 801A 

 Vicious Keyboard

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.

Example

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.

来源: https://cn.vjudge.net/problem/description/79185?1494947481000

题目解读:分成两部分,第一部分直接用strstr数出子串的数量,第二部分判断字符串中有没有修改可以达到目的串的子串,本题中 判断特殊有没有“VVV" ”KKK“

注意:后面试错才发现开头和结尾有特别串可以满足“VV” “KK” 对于串位,直接判断可能会被数据坑。

2017 5 19

代码:

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <cmath>

#include <memory.h>


#define MAX 102

using namespace std;


int main(){

char str[102];

scanf("%s",str);

int ans=0;

char *pstr;


pstr=str;


do{

pstr=strstr(pstr,"VK");

if(pstr){

ans++;

pstr++;

continue;

}else break;


}while(1);

if(strstr(str,"VVV")){

ans++;

}else if(strstr(str,"KK")==str){

ans++;


}else if(strstr(str,"KKK")){

ans++;

}else {

reverse(str,str+strlen(str));

if(strstr(str,"VV")==str)ans++;

}

printf("%d\n",ans);

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  A+B problem