time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.

Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.

A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don’t have to be consecutive, for example, strings “ac”, “bc”, “abc” and “a” are subsequences of string “abc” while strings “abbc” and “acb” are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.

Input

The first line contains string a, and the second line — string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.

Output

If there’s no uncommon subsequence, print “-1”. Otherwise print the length of the longest uncommon subsequence of a and b.

Examples

input

abcd

defgh

output

5

input

a

a

output

-1

Note

In the first example: you can choose “defgh” from string b as it is the longest subsequence of string b that doesn’t appear as a subsequence of string a.

【题目链接】:http://codeforces.com/contest/766/problem/A

【题意】



给你两个串A和B,问你两个串的最长不公共子序列;

【题解】



如果两个串相同;

那么答案就为0;

答案不同的话;

看长度;

直接让长度长的那个串的长度当做答案;

(相同的话任意一个就好)



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int MAXN = 110; string a,b; int main()
{
//freopen("F:\\rush.txt","r",stdin);
cin >> a >> b;
if (a==b)
puts("-1");
else
{
int len1 = a.size(),len2 = b.size();
printf("%d\n",max(len1,len2));
}
return 0;
}

【codeforces 766A】Mahmoud and Longest Uncommon Subsequence的更多相关文章

  1. Codeforces Round #396 (Div. 2) A. Mahmoud and Longest Uncommon Subsequence 水题

    A. Mahmoud and Longest Uncommon Subsequence 题目连接: http://codeforces.com/contest/766/problem/A Descri ...

  2. Codeforces Round #396 (Div. 2) A - Mahmoud and Longest Uncommon Subsequence B - Mahmoud and a Triangle

    地址:http://codeforces.com/contest/766/problem/A A题: A. Mahmoud and Longest Uncommon Subsequence time ...

  3. 766A Mahmoud and Longest Uncommon Subsequence

    A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...

  4. Codeforces766A Mahmoud and Longest Uncommon Subsequence 2017-02-21 13:42 46人阅读 评论(0) 收藏

    A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...

  5. 【codeforces 766C】Mahmoud and a Message

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【codeforces 766D】Mahmoud and a Dictionary

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【codeforces 766B】Mahmoud and a Triangle

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【codeforces 766E】Mahmoud and a xor trip

    [题目链接]:http://codeforces.com/contest/766/problem/E [题意] 定义树上任意两点之间的距离为这条简单路径上经过的点; 那些点上的权值的所有异或; 求任意 ...

  9. Codeforces Round #396(Div. 2) A. Mahmoud and Longest Uncommon Subsequence

    [题意概述] 找两个字符串的最长不公共子串. [题目分析] 两个字符串的最长不公共子串就应该是其中一个字符串本身,那么判断两个字符串是否相等,如果相等,那么肯定没有公共子串,输出"-1&qu ...

随机推荐

  1. FreeMarker中<#include>和<#import>标签的区别

    在使用freemarker作为前端页面模板的应用中,会有很多的freemarker模板页面,这些ftl会在不同的页面中重复使用,一是为了简化布局的管理,二是可以重复使用一些代码. 在freemarke ...

  2. docker相关教程【转】

    https://www.w3cschool.cn/docker/docker-run-command.html 运行容器 https://www.runoob.com/docker/docker-im ...

  3. input的相关兼容性问题

    近来在制作登陆页的input文本框和密码框的时候,具体的实例可参考实现带样式的表单验证,我们发现在IE下默认的情况下,input 标签的密码框和文本框宽度不一致,这就尴尬了. 解决这个办法,我们是直接 ...

  4. LintCode刷题笔记-- Update Bits

    标签: 位运算 描述: Given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to set ...

  5. jQuery图片从下往上滚动效果

    在线演示 本地下载

  6. Excel中IP地址排序

    思路 将IP地址按"."分隔,提取"."之间的每个数,然后根据提取出的列从左至右进行主要字段及次要字段排序 公式说明 返回一个字符串在另一个字符串中出现的起始位 ...

  7. AtCoder Beginner Contest 078 C HSI

    虽说这是个水题,但是我做了大概有一个小时吧,才找到规律,刚学概率,还不大会做题. 找到规律后,又想了想,才想到推导过程. 思路:想要知道花费的时间,就要知道提交的次数,我在这里是计算的提交次数的期望, ...

  8. linux log4cplus安装和实例

    tar –xvf  log4cplus-1.1.3-rc5.tar.gz cd log4cplus-1.1.3-rc5 configure --prefix=/usr/local/log4cplus ...

  9. 前端基础☞html

    HTML 初识 web服务本质 import socket def main(): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s ...

  10. MapReduce数据流-Mapper