766A Mahmoud and Longest Uncommon Subsequence
2 seconds
256 megabytes
standard input
standard 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.
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.
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b.
abcd
defgh
5
a
a
-1
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.
#include <iostream>
#include <string.h>
#include <cmath>
using namespace std; int main()
{
string a, b;
cin >> a >> b;
if(a == b)
cout << - << endl;
else{
int len1 = a.length(), len2 = b.length();
cout << max(len1,len2) << endl;
}
return ;
}
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 ...
- 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 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 ...
- 【codeforces 766A】Mahmoud and Longest Uncommon Subsequence
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces Round #396(Div. 2) A. Mahmoud and Longest Uncommon Subsequence
[题意概述] 找两个字符串的最长不公共子串. [题目分析] 两个字符串的最长不公共子串就应该是其中一个字符串本身,那么判断两个字符串是否相等,如果相等,那么肯定没有公共子串,输出"-1&qu ...
- Longest Uncommon Subsequence I
Given a group of two strings, you need to find the longest uncommon subsequence of this group of two ...
- [LeetCode] Longest Uncommon Subsequence II 最长非共同子序列之二
Given a list of strings, you need to find the longest uncommon subsequence among them. The longest u ...
- [LeetCode] Longest Uncommon Subsequence I 最长非共同子序列之一
Given a group of two strings, you need to find the longest uncommon subsequence of this group of two ...
- [Swift]LeetCode521. 最长特殊序列 Ⅰ | Longest Uncommon Subsequence I
Given a group of two strings, you need to find the longest uncommon subsequence of this group of two ...
随机推荐
- Deep Reinforcement Learning 基础知识
Introduction 深度增强学习Deep Reinforcement Learning是将深度学习与增强学习结合起来从而实现从Perception感知到Action动作的端对端学习的一种全新的算 ...
- CSS滚动条样式设置
webkit浏览器css设置滚动条 主要有下面7个属性 ::-webkit-scrollbar 滚动条整体部分,可以设置宽度啥的 ::-webkit-scrollbar-button 滚动条两端的按钮 ...
- BOM及DOM及事件
知识内容: 1.BOM介绍 2.DOM操作 3.事件 参考:http://www.cnblogs.com/liwenzhou/p/8011504.html 入门代码(DOM基本操作与事件): < ...
- Python序列化和反序列化vsJSON
# -*- coding: utf-8 -* """没有嵌套类的类 author: Jill usage: """ import json ...
- spring boot + jpa + kotlin入门实例
spring boot +jpa的文章网络上已经有不少,这里主要补充一下用kotlin来做. kotlin里面的data class来创建entity可以帮助我们减少不少的代码,比如现在这个User的 ...
- uva-193-图染色-枚举
题意:n个节点,可用描成黑色或者白色,黑节点和黑节点不能相连,问最多描出多少黑节点 #include <iostream> #include <stdio.h> #includ ...
- 15.python操作mysql
导入包 from pymysql import* 1. 创建 Connection 连接 conn=conne(host='192.168.13.130',port=3306 ,database='' ...
- C#--反射技术
反射:反射为了动态(比如动态的加载dll,动态创建类型.动态调用方法等) 引用 using System.Reflection 原理: 一个类库编译后会生成一个以.dll结尾的文件,一个以.pdb结尾 ...
- DOM0和D0M2级事件
1.DOM0级事件:on+事件类型 1.1.在html行内直接绑定, 1.2.在js中绑定 A.DOM0级事件和DOM0级事件相互之间会覆盖,比如以下代码执行后弹出jsDOM0级,js中绑定的事件 覆 ...
- find命令之时间戳使用示例
查看当前目录以及子目录下哪些文件占用的空间最大: find ./ -type f -exec du -m {} \; | sort -nr | head find ./ -type f ...