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 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.
题目链接:http://codeforces.com/contest/801/problem/A
分析:没有人比我更早来切题了吧!无聊的很,做几道题,感觉退了好多,得加油!此题的意思就是要找出KV这个组合,判断a[i+1]=='K'||(a[i]=='V'&&a[i+2]!='K'是否成立,成立+1,否则输出组合情况数!
下面给出AC代码:
1 #include <bits/stdc++.h>
2 using namespace std;
3 int main()
4 {
5 char a[105];
6 cin>>a;
7 int len=strlen(a);
8 int ans=0;
9 int flag=0;
10 for(int i=0;i<len-1;i++)
11 {
12 if(a[i]=='V'&&a[i+1]=='K')
13 {
14 ans++;
15 i++;
16 }
17 else if(a[i+1]=='K'||(a[i]=='V'&&a[i+2]!='K'))
18 flag=1;
19 }
20 cout<<flag+ans<<endl;
21 return 0;
22 }
B. Valued Keys
time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output
You found a mysterious function f. The function takes two strings s1 and s2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function f is another string of the same length. The i-th character of the output is equal to the minimum of the i-th character of s1 and the i-th character of s2.
For example, f("ab", "ba") = "aa", and f("nzwzl", "zizez") = "niwel".
You found two strings x and y of the same length and consisting of only lowercase English letters. Find any string z such that f(x, z) = y, or print -1 if no such string z exists.
Input
The first line of input contains the string x.
The second line of input contains the string y.
Both x and y consist only of lowercase English letters, x and y have same length and this length is between 1 and 100.
Output
If there is no string z such that f(x, z) = y, print -1.
Otherwise, print a string z such that f(x, z) = y. If there are multiple possible answers, print any of them. The string z should be the same length as x and y and consist only of lowercase English letters.
Examples
Input
ab
aa
Output
ba
Input
nzwzl
niwel
Output
xiyez
Input
ab
ba
Output
-1
Note
The first case is from the statement.
Another solution for the second case is "zizez"
There is no solution for the third case. That is, there is no z such that f("ab", z) = "ba".
题目链接:http://codeforces.com/contest/801/problem/B
分析:
思路:判断x[i]是否小于y[i](符合规则),符合就输出y(灵光一闪),否则输出“-1”。
说实在话,我也不是很理解那样例是什么情况!反正就是这样做!
1 #include<bits/stdc++.h>
2 using namespace std;
3 int main()
4 {
5 string x,y;
6 cin>>x>>y;
7 for(int i=0;i<x.size();i++)
8 if(x[i]<y[i])
9 {
10 cout<<-1<<endl;
11 return 0;
12 }
13 cout<<y<<endl;
14 return 0;
15 }
- 总结了一些指针易出错的常见问题(一)
- Eureka 服务上下线监控
- 程序员面试50题(1)—查找最小的k个元素[算法]
- Netty4自带编解码器详解
- C和指针小结(C/C++程序设计)
- Netty-整合Protobuf高性能数据传输
- Netty-整合kryo高性能数据传输
- 40个重要的HTML 5面试问题及答案
- js调用原生API--陀螺仪和加速器
- OpenDaylight开发-DataStoreChange监听器三种类型
- express模拟接口
- spring boot开发的日志系统
- elasticsearch 5.0.1安装analysis-ik分词器
- Spring Cloud中Feign如何统一设置验证token
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法