0519 G2n#W2B-D Valued Keys
来源:互联网 发布:机票比价软件 编辑:程序博客网 时间:2024/05/26 07:29
Valued Keys
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", andf("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".
题目理解:找出由z=f(x,y)得到的y=g(x,z)的表达式即可。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char X[102];
char Z[102];
char Y[102];
int len;
int main(){
scanf("%s%s",X,Z);
len=strlen(X);
bool ans = true;
for(int i=0;i<len;i++){
if(X[i]==Z[i]) Y[i]=Z[i];
else if(X[i]>Z[i]) Y[i]=Z[i];
else {
ans = false;
break;
}
}
if(ans) printf("%s",Y);
else printf("-1");
}
- 0519 G2n#W2B-D Valued Keys
- 0519 G2n#W2B-C Find The Bone
- 0519 G2n#W2B-B Vicious Keyboard
- 0519 G2n#W2B-A Buying A House
- B. Valued Keys
- Codeforces801B Valued Keys
- Codeforces801B Valued Keys
- B. Valued Keys
- Valued Keys- Codeforce
- Codeforces 801B Valued Keys
- CodeForces 801B Valued Keys
- codeforces 801B Valued Keys
- Codeforces Round #409 (Div. 2) B. Valued Keys
- CF#801 B. Valued Keys(字符串,贪心)
- 0526 CF#801A&G2n#D-Straight «A»
- 0519 G2n#W2A-B 盐水的故事
- 0519 G2n#W2A-A 解方程
- CodeForces 831D Office Keys
- 如何写出简洁优美的CSS Reset
- struts2中整合FreeMarker案例
- Android 解决启动界面显示空白问题
- C++ STL容器时间复杂度下的最佳选择
- 打开wireshark出现the file"..."doesn't exist/couldn't create signal pipe...
- 0519 G2n#W2B-D Valued Keys
- 【微营销】第2天 微营销实战技巧之官方微博、品牌微博、产品微博、专业知识微博
- Hibernate之查询
- 2017中北大学程序设计大赛决赛题解
- FFmpeg常用命令记录(1):录取屏幕、剪切视频、将视频转化为GIF
- jquery入口函数
- PageRank算法
- Enemy is weak
- Swift 文件 只有 import Foundation 而需要UIViewController