0519 G2n#W2B-B Vicious Keyboard

摘要:判断给定 最多可修改一个字符后的 字符串 中  特殊子串的数量。 
原题目: 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.


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

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

代码:
   
   
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <memory.h>
  6. #define MAX 102
  7. using namespace std;
  8. int main(){
  9. char str[102];
  10. scanf("%s",str);
  11. int ans=0;
  12. char *pstr;
  13. pstr=str;
  14. do{
  15. pstr=strstr(pstr,"VK");
  16. if(pstr){
  17. ans++;
  18. pstr++;
  19. continue;
  20. }else break;
  21. }while(1);
  22. if(strstr(str,"VVV")){
  23. ans++;
  24. }else if(strstr(str,"KK")==str){
  25. ans++;
  26. }else if(strstr(str,"KKK")){
  27. ans++;
  28. }else {
  29. reverse(str,str+strlen(str));
  30. if(strstr(str,"VV")==str)ans++;
  31. }
  32. printf("%d\n",ans);
  33. return 0;
  34. }



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值