zoukankan      html  css  js  c++  java
  • E

    E - 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 thei-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.

    Example

    Input
    ab
    aa
    Output
    ba
    Input
    nzwzl
    niwel
    Output
    xiyez
    Input
    ab
    ba
    Output
    -1
    题意:输入两个长度相等的小写字符串x,y,能否找到字符串z,从第一个字符到最后一个字符,比较x,z,把最小的字符给y,即f(x, z) = y;如果z存在,就输出,否则输出-1;
    题解:分类讨论:1.当x[i]=y[i] z[i]=x[i];
             2.当x[i]<y[i] z[i]不存在;
             3.当x[i]>y[i] z[i]=y[i];
    代码
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<cstdlib>
    #include<cmath>
    #include<cstdio>
    using namespace std;
    int main()
    {
        string str1,str2;
        char ans[105];
        int i,j,len,t;
        while(cin>>str1>>str2){
            t=1;
            len=str1.size();
            for(i=0;i<len;i++)
            {
                if(str1[i]==str2[i])
                {
                    ans[i]=str1[i];
                }
                else
                {
                    if(str1[i]<str2[i])
                    {
                        t=0;
                        break;
                    }
                    else
                    {
                        ans[i]=str2[i];
                    }
                }
            }
            if(t==0)
                cout<<-1;
            else
                {
                    for(i=0;i<len;i++)
                        printf("%c",ans[i]);
                }
                cout<<endl;
        }
    }
  • 相关阅读:
    爬取笔趣阁小说(一念永恒)
    爬虫requests爬去网页乱码问题
    requests bs4 datetime re json
    添加背景音乐。c
    strip()
    爬虫学习中遇到的问题
    super的用法(带了解)
    user-agent
    输入n个字符串,用空格隔开。这些字符串中有重复出现的。现在统计每个字符串出现的次数,并找出出现次数最多的字符串。
    字节跳动小程序的一些坑
  • 原文地址:https://www.cnblogs.com/GXXX/p/6814574.html
Copyright © 2011-2022 走看看