Codeforces Round #396 (Div. 2) A. Mahmoud and Longest Uncommon Subsequence 水题
A. Mahmoud and Longest Uncommon Subsequence
题目连接:
http://codeforces.com/contest/766/problem/A
Description
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.
Sample Input
abcd
defgh
Sample Output
5
Hint
题意
求两个串的最长不公共子序列
题解:
其实答案就两个,要么是-1,要么就是最长的长度,这个思考一下就好了。
代码
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main()
{
cin>>a>>b;
if(a==b){
cout<<"-1"<<endl;
}else
cout<<max(a.size(),b.size())<<endl;
}
Codeforces Round #396 (Div. 2) A. Mahmoud and Longest Uncommon Subsequence 水题的更多相关文章
- 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 Round #396(Div. 2) A. Mahmoud and Longest Uncommon Subsequence
[题意概述] 找两个字符串的最长不公共子串. [题目分析] 两个字符串的最长不公共子串就应该是其中一个字符串本身,那么判断两个字符串是否相等,如果相等,那么肯定没有公共子串,输出"-1&qu ...
- Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary 并查集
D. Mahmoud and a Dictionary 题目连接: http://codeforces.com/contest/766/problem/D Description Mahmoud wa ...
- Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary
地址:http://codeforces.com/contest/766/problem/D 题目: D. Mahmoud and a Dictionary time limit per test 4 ...
- Codeforces Round #356 (Div. 2)B. Bear and Finding Criminals(水题)
B. Bear and Finding Criminals time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- Codeforces Round #343 (Div. 2) A. Far Relative’s Birthday Cake 水题
A. Far Relative's Birthday Cake 题目连接: http://www.codeforces.com/contest/629/problem/A Description Do ...
- Codeforces Round #396 (Div. 2) E. Mahmoud and a xor trip dfs 按位考虑
E. Mahmoud and a xor trip 题目连接: http://codeforces.com/contest/766/problem/E Description Mahmoud and ...
- Codeforces Round #396 (Div. 2) C. Mahmoud and a Message dp
C. Mahmoud and a Message 题目连接: http://codeforces.com/contest/766/problem/C Description Mahmoud wrote ...
- Codeforces Round #396 (Div. 2) B. Mahmoud and a Triangle 贪心
B. Mahmoud and a Triangle 题目连接: http://codeforces.com/contest/766/problem/B Description Mahmoud has ...
随机推荐
- Training (deep) Neural Networks Part: 1
Training (deep) Neural Networks Part: 1 Nowadays training deep learning models have become extremely ...
- ant+sonar+jacoco代码质量代码覆盖率扫描
使用ant构建的java web项目如何做sonar代码质量扫描?以下就是实际遇到并成功使用的案例一.做sonar扫描的准备工作 1.给web项目增加build.xml构建脚本. 2.下载 ...
- 【干货】使用EnCase来分析windows 7文件系统------认识元数据记录$MFT,数据恢复
来源:Unit 6: Windows File Systems and Registry 6.1 Windows File Systems and Registry Windows NTFS File ...
- MySQL Dual-Master 双向同步
本文介绍的Mysql Dual-Master 复制实施方法可能不是最完美.最强大的.但是在我的应用环境下能很好的满足各项需求. 本文基于我们仅仅使用两台MySQL服务器的情况下,但是你会发现文章中介绍 ...
- MySQL之EXPLAIN 执行计划详解
explain 可以分析 select 语句的执行,即 MySQL 的“执行计划. 一.type 列 MySQL 在表里找到所需行的方式.包括(由左至右,由最差到最好): | All | index ...
- 001_fpm打包命令详解
使用fpm来制作rpm包 2017/2/22 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 ...
- 几种list排序方法
package com.lgx.jdk8.part02; import java.util.*; import java.util.stream.Collectors; /** * Comparato ...
- @PostContruct注解
@PostContruct是spring框架的注解,在方法上加该注解会在项目启动的时候执行该方法,也可以理解为在spring容器初始化的时候执行该方法.
- RandomForest随机森林总结
1.随机森林原理介绍 随机森林,指的是利用多棵树对样本进行训练并预测的一种分类器.该分类器最早由Leo Breiman和Adele Cutler提出,并被注册成了商标.简单来说,随机森林就是由多棵CA ...
- 如何批量删除word文档中的超级链接?
有时候从网页上copy来的文章中,会带有非常多的链接,这些链接很烦人是吧?如何批量删除(一次性全部删除)word文章中的超链接呢? 有些朋友说,Ctrl+A全选文章,然后点击格式工具栏上的“清除格式” ...