Codeforces766A Mahmoud and Longest Uncommon Subsequence 2017-02-21 13:42 46人阅读 评论(0) 收藏
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.
——————————————————————————————————————
水题,题目的意思是在两个字符串中选一个字符串取他的子序列,使得这个子序列不是另一个字符串的子序列,问最长取多大?
直接判字符串一样输出-1,不一样输出长的那个
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN=100005; char a[MAXN];
char b[MAXN]; int main()
{
while(~scanf("%s%s",a,b))
{
if(strcmp(a,b)==0)
printf("-1\n");
else
printf("%d\n",max(strlen(a),strlen(b)));
} return 0;
}
Codeforces766A Mahmoud and Longest Uncommon Subsequence 2017-02-21 13:42 46人阅读 评论(0) 收藏的更多相关文章
- PAT甲 1007. Maximum Subsequence Sum (25) 2016-09-09 22:56 41人阅读 评论(0) 收藏
1007. Maximum Subsequence Sum (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...
- Codeforces 766C Mahmoud and a Message 2017-02-21 13:57 62人阅读 评论(0) 收藏
C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces766B Mahmoud and a Triangle 2017-02-21 13:47 113人阅读 评论(0) 收藏
B. Mahmoud and a Triangle time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces 632D Longest Subsequence 2016-09-28 21:29 37人阅读 评论(0) 收藏
D. Longest Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- POJ2061 Subsequence 2017-05-25 19:49 83人阅读 评论(0) 收藏
Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14709 Accepted: 6210 Desc ...
- HDU6027 Easy Summation 2017-05-07 19:02 23人阅读 评论(0) 收藏
Easy Summation Time Limit: 2000/1000 MS ...
- Hdu4632 Palindrome subsequence 2017-01-16 11:14 51人阅读 评论(0) 收藏
Palindrome subsequence Problem Description In mathematics, a subsequence is a sequence that can be d ...
- Codeforces 766D Mahmoud and a Dictionary 2017-02-21 14:03 107人阅读 评论(0) 收藏
D. Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input ...
- hdu 1082, stack emulation, and how to remove redundancy 分类: hdoj 2015-07-16 02:24 86人阅读 评论(0) 收藏
use fgets, and remove the potential '\n' in the string's last postion. (main point) remove redundanc ...
随机推荐
- Mysql root 用户密码忘记后重置root密码
[windows] 1.停止mysql服务:打开命令行窗口CMD,Net stop mysql 2.用另外一种方式启动Mysql:在命令行进入到mysql的安装路径下的bin目录下使用 mysqld- ...
- 华硕主板P8H61(P8H61-M_LX3_PLUS_R2.0)成功禁用USB口
公司大批这个型号的主板,在百度上搜索了一下,其中有一篇帖子说华硕客服说这个型号的USB控制XX是集成成南桥上面没法禁止. 经过研究发现官网上的0802版可以支持禁止usb,并且可以根据需要为每一个US ...
- xhprof使用
一.下载安装 wget http://pecl.php.net/get/xhprof-0.9.3.tgz tar zxvf xhprof-0.9.3.tgz cd xhprof-0.9.3/exten ...
- scrollWidth,clientWidth,offsetWidth的区别 ---转载的
转载自博客:http://www.cnblogs.com/kongxianghai/p/4192032.html 通过一个demo测试这三个属性的差别. 说明: scrollWidth:对象的实际内容 ...
- java web 程序---javabean实例--登陆界面并显示用户名和密码
重点:注意大小写,不注意细节,这点小事,还需要请教 发现一个问题,也是老师当时写的时候,发现代码没错,但是就是运行问题. 大家看,那个java类,我们要求是所有属性均为私有变量,但是方法为公有的,如果 ...
- java websocket @ServerEndpoint注解说明
http://www.blogjava.net/qbna350816/archive/2016/07/24/431302.html https://segmentfault.com/q/1010000 ...
- MS-TEST 批处理执行测试时的资源文件目录问题
What: 使用MS-TEST的 批处理执行它的测试 DLL 时,如: MSTest /testcontainer:C:\David\ADAccountGIT\AdAccountMSTest\ADA ...
- python 爬虫气象气象定时报 气象预警推送
"2018-04-09 14时""长沙市""10日(明天)""多云转雷阵雨""29℃""1 ...
- javascript的中的new
考察 ECMAScript 语言规范中 new 运算符的定义: The new Operator The production NewExpression : new NewExpression is ...
- Apache Hadoop 集群安装文档
简介: Apache Hadoop 集群安装文档 软件:jdk-8u111-linux-x64.rpm.hadoop-2.8.0.tar.gz http://www.apache.org/dyn/cl ...