[CodeForce 801A] Vicious Keyboard
题目链接:http://codeforces.com/problemset/problem/801/A
思路:题目中字符串的长度最长100个字符,所以,可以考虑用暴力,先遍历一遍匹配“VK”的,并把符合条件的标记成其他的字符(如'$'),然后再遍历一遍,只要找到符合"VV"或者"KK"的,就把答案加1,然后跳出循环,然后输出答案即可。
AC代码:
#include<cstdio>
#include<cstring>
using namespace std;
int main() {
char arr[102];
int cnt;
while (scanf("%s", arr) != EOF) {
cnt = 0;
for (int i = 1; i < strlen(arr); i++) {
if (arr[i - 1] == 'V' && arr[i] == 'K') {
cnt++;
arr[i - 1] = arr[i] = '$';
}
}
for (int i = 0; i < strlen(arr) - 1; i++) {
if (arr[i] == arr[i + 1] && (arr[i] == 'V' || arr[i] == 'K')) {
cnt++;
break;
}
}
printf("%d\n", cnt);
memset(arr, 0, strlen(arr));
}
return 0;
}
[CodeForce 801A] Vicious Keyboard的更多相关文章
- AC日记——Vicious Keyboard codeforces 801a
801A - Vicious Keyboard 思路: 水题: 来,上代码: #include <cstdio> #include <cstring> #include < ...
- Codeforces801A Vicious Keyboard 2017-04-19 00:16 241人阅读 评论(0) 收藏
A. Vicious Keyboard time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces 801 A.Vicious Keyboard & Jxnu Group Programming Ladder Tournament 2017江西师大新生赛 L1-2.叶神的字符串
A. Vicious Keyboard time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Vicious Keyboard CodeForces - 801A (暴力+模拟)
题目链接 题意: 给定一个字符串,最多更改一个字符,问最多可以有多少个“VK”子串? 思路: 由于数据量很小,不妨尝试暴力写.首先算出不更改任何字符的情况下有多个VK字串,然后尝试每一次更改一个位置的 ...
- 【codeforces 801A】Vicious Keyboard
[题目链接]:http://codeforces.com/contest/801/problem/A [题意] 一个字符串只由VK组成; 让你修改一个字符; 使得剩下的字符串里面子串VK的个数最大; ...
- CodeForces801-A.Vicious Keyboard-暴力
A. Vicious Keyboard time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2)(A.思维题,B.思维题)
A. Vicious Keyboard time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) 题解【ABCDE】
A. Vicious Keyboard 题意:给你一个字符串,里面只会包含VK,这两种字符,然后你可以改变一个字符,你要求VK这个字串出现的次数最多. 题解:数据范围很小,暴力枚举改变哪个字符,然后c ...
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) A B C D 暴力 水 二分 几何
A. Vicious Keyboard time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- html5-微格式-时间的格式
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- 配置tomcat的https域名
配置tomcat的https域名: <Connector port=" protocol="org.apache.coyote.http11.Http11NioProtoco ...
- django之路由分析
URL配置(URLconf)就像Django所支撑网站的目录.它的本质是URL与要为该URL调用的视图函数之间的映射表. URLconf配置 基本格式: from django.conf.urls i ...
- Linux基础命令---修改用户信息usermod
usermod 修改用户的信息,包括用户名.密码.家目录.uid等. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE.Fedora. 1.语法 use ...
- 专题8:javascript函数详解
函数是一段可以反复调用的代码块.函数还能接受输入的参数,不同的参数会返回不同的值. 函数的声明 JavaScript 有三种声明函数的方法. (1)function 命令 function命令声明的代 ...
- JS报错修改日记(1):Uncaught ReferenceError: showQRcode is not defined
为了加一个查看二维码的功能,如: //页面内按钮 <a class="manipulate-btn" href="#" onclick="sho ...
- Step by Step use OBD2 Scanner Guide
Learning to use a good automotive OBD2 code reader is one of the best ways you can continually inves ...
- 相关Linux命令
#若服务不小心开启但是想关闭时,可以使用这个 命令:adstrtal.sh apps/apps(脚本 数据库用户名/密码) 若想启动命令:adstrtal.sh apps/apps ———————— ...
- centos系统swap设置 查看swap分区的方法
交换分区swap,意思是“交换”.“实物交易”,它的功能就是在内存不够的情况下,操作系统先把内存中暂时不用的数据,存到硬盘的交换空间,腾出内存来让别的程序运行,和Windows的虚拟内存(pagefi ...
- Java排序之升序与降序
以前在学校学排序的时候,总是自己写排序的代码,真正到工作中,直接使用java提供的排序方法,但最近发现行业默认的和学习时有些不一样. 以前总是在进行排序时如果前边的数字和后边数字的差为负则交换两个数字 ...