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
Output
Input
Output
Input
Output
Input
Output
Input
Output
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
代码:
原题目: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;
}
相关文章推荐
- 0519 G2n#W2B-D Valued Keys
- 0519 G2n#W2B-C Find The Bone
- 0519 G2n#W2B-A Buying A House
- 0519 G2n#W2A-E 2 Strings bang bang bang
- 0519 G2n#W2A-C Ignatius and the Princess IV
- 0519 G2n#W2A-B 盐水的故事
- 0519 G2n#W2A-A 解方程
- 如何在VxWorks下为TAU G2的程序设置断点
- G1->I7500->G2,手机原来可以这么有趣
- RFID UHF Class1 G2 卡结构说明
- G2 DT时代的图形语法 正式发布
- 0519
- ubuntu系统下,hp 650 G2笔记本合上盖子后不进入睡眠状态的问题
- G2 手机新概念
- Android G2手机如何使用CMWAP上网
- LG:G2 Google TV将于下周面世
- 细谈曲面G1、G2、G3与G4连续
- 源码推荐(0519):PickerView,星星形状的评分进度条
- 0519