深夜切题——Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2)

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.

思路;

FOR循环识别VK计数然后替换掉(除'V''K'外都可以)

FOR循环识别VV或者VK 计数加一退出循环

即可

#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main() {
    char s[105];
    gets(s);
    int length=strlen(s),c=0;
    for(int i=0;i<length-1;++i)
    {
        if(s[i]=='V'&&s[i+1]=='K')
        {
            s[i++]='0';
            s[i]='0';
            ++c;
        }
    }
    for(int i=0;i<length-1;++i)
    {
        if(s[i]=='V'&&s[i+1]=='V'||s[i]=='K'&&s[i+1]=='K')
        {
            ++c;
            break;
        }
    }
    printf("%d\n",c);
    return 0;
}
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".


思路:判断x[i]是否小于y[i](符合规则),符合就输出y(灵光一闪),否则输出“-1”。
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

int main() {
    char x[105],y[105];
    gets(x);gets(y);
    int l=strlen(x),flag=0;
    for(int i=0;i<l;++i)
    {
        if(x[i]<y[i])
        {
            flag=1;
            break;
        }
    }
    if(flag)
        printf("-1\n");
    else
        puts(y);
    return 0;
}

Verdict:Pretests passed 
切完水题睡觉。。。静候最终结果(不会这都错吧- -)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值