A. Vicious Keyboard
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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.

————————————————————————————————————

题目的意思是给出一个只含VK的字符串,你可以把其中一个换成另一个,问最多有几个VK

思路先跑一边记录有几个VK并标记,在搜一遍有没有相邻的没被标记过的可以构成VK的

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue> using namespace std; int main()
{
char s[105];
int a[105];
while(~scanf("%s",s))
{
memset(a,0,sizeof a);
int k=strlen(s);
int ans=0;
for(int i=0;i<k-1;i++)
{
if(s[i]=='V'&&s[i+1]=='K')
{
a[i]=a[i+1]=1;
ans++;
i++;
}
}
for(int i=0;i<k-1;i++)
{
if((s[i]=='V'||s[i+1]=='K')&&a[i]==0&&a[i+1]==0)
{
ans++;
break;
}
}
printf("%d\n",ans);
} return 0;
}

Codeforces801A Vicious Keyboard 2017-04-19 00:16 241人阅读 评论(0) 收藏的更多相关文章

  1. Python解析HDF文件 分类: Python 2015-06-25 00:16 743人阅读 评论(0) 收藏

    前段时间因为一个业务的需求需要解析一个HDF格式的文件.在这之前也不知道到底什么是HDF文件.百度百科的解释如下: HDF是用于存储和分发科学数据的一种自我描述.多对象文件格式.HDF是由美国国家超级 ...

  2. Hdu 1506 Largest Rectangle in a Histogram 分类: Brush Mode 2014-10-28 19:16 93人阅读 评论(0) 收藏

    Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  3. OC基础:Date 分类: ios学习 OC 2015-06-22 19:16 158人阅读 评论(0) 收藏

    NSDate  日期类,继承自NSObject,代表一个时间点 NSDate *date=[NSDate date]; NSLog(@"%@",date);   //格林尼治时间, ...

  4. HDU4081 Qin Shi Huang's National Road System 2017-05-10 23:16 41人阅读 评论(0) 收藏

    Qin Shi Huang's National Road System                                                                 ...

  5. 公众号第三方平台开发 获取 component_verify_ticket 2015-07-05 10:16 59人阅读 评论(0) 收藏

    8.推送component_verify_ticket协议 在公众号第三方平台创建审核通过后,微信服务器会向其"授权事件接收URL"每隔10分钟定时推送component_veri ...

  6. How to create your own custom 404 error page and handle redirect in SharePoint 分类: Sharepoint 2015-07-08 00:22 4人阅读 评论(0) 收藏

    1. In your MOSS server, make a copy of %systemdrive%\Program Files\Common Files\Microsoft Shared\Web ...

  7. C/C++中const的用法 分类: C/C++ 2015-07-05 00:43 85人阅读 评论(0) 收藏

    const是C语言的关键字,经C++进行扩充,变得功能强大,用法复杂.const用于定义一个常变量(只读变量),当const与指针,引用,函数等结合起来使用时,情况会变得复杂的多.下面将从五个方面总结 ...

  8. 自动化测试工具QTP的使用实例 分类: 软件测试 2015-06-17 00:23 185人阅读 评论(0) 收藏

    1. QTP简介 1.1QTP功能与特点 QTP是QuickTest Professional的简称,是一种自动化软件测试工具.在软件的测试过程中,QTP主要来用来通过已有的测试脚本执行重复的手动测试 ...

  9. 2012年"浪潮杯"山东省第三届ACM大学生程序设计竞赛--n a^o7 ! 分类: 比赛 2015-06-09 17:16 14人阅读 评论(0) 收藏

    n a^o7 ! Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 All brave and intelligent fighte ...

随机推荐

  1. Spring的国际化(转载)

    1:在MyEclipse下面创建一个test的Web  Project,然后添加Spring相关的文件,在src根目录下创建applicationContext.xml文件. applicationC ...

  2. Python——序列

    #!/usr/bin/python #coding:utf8 ''' Python——序列 字符串的操作 ''' s = 'abcdefg' print s print s[2] print s[-1 ...

  3. Linux就业技术指导(六):天津IDC机房项目实践

    一,天津IDC机房项目图片介绍 服务器DELL R720 二,远程控制卡配置方法 远程控制卡,在服务器没有装操作系统或者操作系统出问题了.用户可以通过连接到远程控制卡来连接服务器,就如同切换到我们的虚 ...

  4. jsp页面添加时间

    <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <body& ...

  5. 正向工程configuration配置连接

    在执行正向工程的时候需要用到这个关键词里面的configure();方法, 这个方法有好几个重构, 都是参数不一样的, 也可以空着不写, 不写的话就会默认去找hibernate.cfg.xml这个文件 ...

  6. 利用简单的参数传递来实现单条查询的easyui-datagrid

    前一阵子老师给出了一个题目, 说让设计个表格, 学生系统的, 可以查询学生的信息和成绩, 科目自己定, 数据库建表也自己定. 数据库的建表可是建的相当的简陋, 反正老师不是很满意, 后来数据表格做出来 ...

  7. 百度BAE部署微信开发环境

    这里会弹出一个SVN的账户和密码,这个账户和密码就是你百度的账户和密码 将项目导出WAR包到SVN的客户端目录里面 然后右键SVN Commit提交代码 部署列表有新版本 快捷发布 tocken认证失 ...

  8. Python3 len()方法

    Python3 len()方法  Python3 字符串 描述 Python len() 方法返回对象(字符.列表.元组等)长度或项目个数. 语法 len()方法语法: len( s ) 参数 s - ...

  9. A计划(BFS)

    A计划 http://acm.hdu.edu.cn/showproblem.php?pid=2102 Time Limit: 3000/1000 MS (Java/Others)    Memory ...

  10. iOS 代码调试

    僵尸对象导致crash(Thread 1:EXC_BAD_ACCESS(code=EXC_I386_GPFLT)),需要给位release模式,debug模式不打印内存地址 https://blog. ...