CF#801 B. Valued Keys(字符串,贪心)

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".


题意:定义f ( x , y ) 的功能是对字符串 x 、y 每一位 x[ i ] ,  y[ i ] 取ascll值小的字符,现有z = f ( x ,y ) ,给出 x 和 z ,求 y,如不存在则输出 -1。


#include <bits/stdc++.h>
using namespace std;

const int N = 100 + 10;
char a[N], b[N], c[N];

int main()
{
    while(~scanf("%s%s", a, b))
    {
        memset(c, 0, sizeof(c));
        int l = strlen(a), flag = 0;
        for(int i = 0; i < l; i++)
        {
            if(b[i] > a[i]) flag = 1;
            if(a[i] == b[i]) c[i] = 'z';
            else c[i] = b[i];
        }
        if(flag) printf("-1\n");
        else printf("%s\n", c);
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用SQL Server中的表值参数(Table-valued parameter,TVP)来传递字符串数组给存储过程。 具体的做法是,首先在数据库中创建一个类型为Table type的对象,这个对象定义了一个表结构,用于存储传递的字符串数组。例如,可以创建一个名为`POList`的Table type对象,该对象包含一个名为`PONumber`的列,用于存储传递的PO Number。 创建完Table type对象后,可以在存储过程的参数列表中添加一个参数,类型为上面创建的Table type对象。在存储过程中,可以将这个参数作为输入参数,使用类似于以下的语句来获取传递的字符串数组: ``` DECLARE @POList POListType; INSERT INTO @POList (PONumber) VALUES ('PO111'), ('PO112'), ('PO113'); ``` 这样就可以将字符串数组传递给存储过程,然后在存储过程中使用T-SQL语句来处理这个数组。例如,可以使用以下的语句来查询这个数组中的PO Number: ``` SELECT PONumber FROM @POList; ``` 在C#代码中,可以使用DataTable来表示这个Table type对象,然后将DataTable传递给存储过程。例如,在C#代码中可以使用以下的语句来创建一个包含多个PO Number的DataTable: ``` DataTable poList = new DataTable(); poList.Columns.Add("PONumber"); poList.Rows.Add("PO111"); poList.Rows.Add("PO112"); poList.Rows.Add("PO113"); ``` 然后可以将这个DataTable作为参数传递给存储过程,例如: ``` using (SqlCommand cmd = new SqlCommand("MyStoredProcedure", conn)) { cmd.CommandType = CommandType.StoredProcedure; SqlParameter poListParam = cmd.Parameters.AddWithValue("@POList", poList); poListParam.SqlDbType = SqlDbType.Structured; poListParam.TypeName = "dbo.POListType"; // ... add other parameters ... // execute the stored procedure SqlDataReader reader = cmd.ExecuteReader(); // ... } ``` 这样就可以将字符串数组传递给存储过程了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值