Practice_Codeforces Round #409 (Div. 2)
来源:互联网 发布:删除表的sql语句 编辑:程序博客网 时间:2024/05/16 16:04
蒟蒻的水题之路
根据外国友人的建议,有效的做题。
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.
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 a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character.
VK
1
VV
1
V
0
VKKKKKKKKKVVVVVVVVVK
3
KVKV
1
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
//VVKKVKKVVKKVKKVKVVKKVKKVVKKVKVVKKVKKVKVVKKVVKKVKVVKKVKVVKKVVKVVKKVKKVKKVKKVKKVKVVKKVKKVKKVKKVKKVVKVK#include <iostream>using namespace std;int main(){ ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int cnt = 0; if (s.length() == 1) { cout << "0\n"; return 0; } int l = s.length(); for (int i = 0; i < l - 1; i++) if(s[i] == 'V' && s[i+1] == 'K') cnt++; if((s[0] == 'K' && s[1] == 'K')) cnt++; else if (s[l-1] == 'V' && s[l-2] == 'V') cnt++; else { for (int i = 0; i < l - 2; i++) { if(s[i] == s[i+1] && s[i] == s[i+2]) { cnt++; break; } } } cout << cnt << endl; return 0;}
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.
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.
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.
abaa
ba
nzwzlniwel
xiyez
abba
-1
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".
#include <iostream>using namespace std;int main(){ ios::sync_with_stdio(false); cin.tie(0); string x, y; cin >> x >> y; int l = x.length(); for (int i = 0; i < l; i++) if (y[i] > x[i]) { cout << "-1\n"; return 0; } cout << y << endl; return 0;}
The end.
- Practice_Codeforces Round #409 (Div. 2)
- Practice_Codeforces Round #410 (Div. 2)
- Practice_Codeforces Round #408 (Div. 2)
- Practice_Codeforces Round #407 (Div. 2)
- Practice_Codeforces Round #406 (Div. 2)
- Practice_Codeforces Round #405 (Div. 2)
- Practice_Codeforces Round #404 (Div. 2)
- Practice_Codeforces Round #411 (Div. 2)
- Practice_Codeforces Round #412 (Div. 2)
- Practice_Codeforces Round #413 (Div. 2)
- Codeforces Round #409 (Div. 2)
- Codeforces Round #409 (Div. 2)
- Codeforces Round #409 Div. 2(A+B)
- Codeforces Round #409 (Div. 2) ABCDE
- Round #146(Div 2)
- Round #145(Div 2)
- Round #338 (Div. 2)
- Round #292 (Div. 2)
- springmvc乱码问题
- Python isinstance
- Python(Pycharm)连接Oracle数据库之cx_Oracle的使用(cx_Oracle在pyCharm中报错)
- 黑马程序员 十、IO 文件操作(2)
- 24c02存储花样灯
- Practice_Codeforces Round #409 (Div. 2)
- linux合并文件
- 机器学习之K近邻简介
- linux 文件每行行尾追加字符
- 56-套接字选项(TCP_CORK)
- 1354 选数字 (背包)
- UVa 900題記錄
- ℃江让您从精通到入门:Android如何知晓自己身在哪个Activity
- 黑马程序员 十一、网络编程