【codeforces 766A】Mahmoud and Longest Uncommon Subsequence
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的更多相关文章
- 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 ...
- 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 ...
- 766A Mahmoud and Longest Uncommon Subsequence
A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...
- 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 ...
- 【codeforces 766C】Mahmoud and a Message
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 766D】Mahmoud and a Dictionary
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 766B】Mahmoud and a Triangle
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 766E】Mahmoud and a xor trip
[题目链接]:http://codeforces.com/contest/766/problem/E [题意] 定义树上任意两点之间的距离为这条简单路径上经过的点; 那些点上的权值的所有异或; 求任意 ...
- Codeforces Round #396(Div. 2) A. Mahmoud and Longest Uncommon Subsequence
[题意概述] 找两个字符串的最长不公共子串. [题目分析] 两个字符串的最长不公共子串就应该是其中一个字符串本身,那么判断两个字符串是否相等,如果相等,那么肯定没有公共子串,输出"-1&qu ...
随机推荐
- JSP Web第八章整理复习 过滤器
P269 Filter过滤器的基本原理 P269 Filter过滤器体系结构 原理和体系结构看懂了就行 P270 例8-1过滤器代码与配置文件 略
- 一文读懂JVM
(一)JVM 基础知识 1)Java 是如何实现跨平台的? 注意:跨平台的是 Java 程序,而不是 JVM.JVM 是用 C/C++ 开发的,是编译后的机器码,不能跨平台,不同平台下需要安装不同版本 ...
- c++中的c_str()函数
//c_str()是为了与C语言兼容,把c++中string类型的字符串返回首地址使用 #include <iostream>#include <string.h>using ...
- D3D10/11中的遮挡查询的使用
原文:D3D10/11中的遮挡查询的使用 在D3D10/11中,有D3D10_QUERY/D3D11_QUERY接口,通过QUERY接口,我们可以查询GPU的一些状态,比如GPU的时间戳信 ...
- Directx11教程(56) 建立一个skydome
原文:Directx11教程(56) 建立一个skydome 本章建立一个skydome(天空穹),主要学习如何使用cube mapping. cube map就是把六张纹理当作 ...
- python 正则表达式简介
- iOS 万能跳转界面方法 (runtime实用篇一)
http://www.cocoachina.com/ios/20150824/13104.html 作者:汉斯哈哈哈 授权本站转载. 在开发项目中,会有这样变态的需求: 推送:根据服务端推送过来的数据 ...
- 实现一个简易的promise
//promise里面只有三个状态,且三个状态的转换形式有两种 //由pending转换为fulfilled,由pending转换为rejected //Promise的构造函数参数是一个函数,函数的 ...
- Centos7环境下搭建Nginx+Lua+Redis进行数据存取
1.安装依赖环境 yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel 2.安装LuaJIT cd /usr/loca ...
- hdu 2412 Party at Hali-Bula【树形dp】
HDU 2412 和poj 2342(hdu 1520)差不多,多了一个判断最优解是(Yes)否(No)唯一.关键问题也在这个判断最优解是否唯一上. 先定义dp[u][2],表示选(dp[][1])或 ...