【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 ...
随机推荐
- 一眼看穿👀JS基本概念
前段时间忙,好久没更新了,继续梳理基础知识这期总结的是JS的基本概念 标识符 所谓的标识符是指变量,函数属性的名字,或者函数的参数 第一个字符必须是一个字母,下划线(_)或者一个美元符号($),其他字 ...
- day38 12-Spring的Bean的属性的注入:名称空间p
xmlns="http://www.springframework.org/schema/beans"是默认的名称空间. xmlns:xsi="http://www.w3 ...
- C++11中的并发
在 C++98 的时代,C++标准并没有包含多线程的支持,人们只能直接调用操作系统提供的 SDK API 来编写多线程程序,不同的操作系统提供的 SDK API 以及线程控制能力不尽相同.到了 C++ ...
- Leaflet地图框架使用手册
因为要做一个交通仿真项目,需要用到这个地图库,但是查询官方API麻烦,而且这个地图框架的API做的用起来确实太麻烦了..就从网上各种地方查找了一些,方便用, 大多都是复制,,见谅!! L.Map AP ...
- 洛谷2501 BZOJ1801中国象棋题解
题目链接 BZ链接 其实dp只要把状态想好后转移就很好写了(flag*1) f[i][j][k]表示到了第i行,有j列放了一个跑,有k列放了两个跑的方案总数 然后大力讨论,转移即可 # include ...
- QT窗口无边框最前
this->setWindowFlags(Qt::WindowStaysOnTopHint| Qt::CustomizeWindowHint| Qt::Tool| Qt::FramelessWi ...
- 用dreamweaver查找页面位置
复制页面的一段代码,然后用Dreamweaver在整个项目中查找代码. 找不到的原因:1.查找的内容是从数据库中读出来的.连数据库文件一起查便知. 2.查找的代码是某个函数生成的.
- 人生苦短,LET'S GO! GO语言目录
1.Golang开山篇,GO就是NB! 1-1.go开发工具安装 2.go-人生第一个go程序和基本语法 3.go-流程控制 4.go-函数 5.go-流程控制 6.go-复合类型 7.go-面向对象 ...
- 小爬爬4:selenium操作
1.selenium是什么? selenium: - 概念:是一个基于浏览器自动化的模块. - 和爬虫之间的关联? - 帮我我们便捷的爬取到页面中动态加载出来的数据 - 实现模拟登陆 - 基本使用流程 ...
- Effective C++: 04设计与声明
18:让接口容易被正确使用,不易被误用 1:理想上,如果客户企图使用某个接口而却没有获得他所预期的行为,这个代码不该通过编译:如果代码通过了编译,它的作为就该是客户所想要的. 2:许多客户端的错误可以 ...