A. Mahmoud and Longest Uncommon Subsequence
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

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.

——————————————————————————————————————

水题,题目的意思是在两个字符串中选一个字符串取他的子序列,使得这个子序列不是另一个字符串的子序列,问最长取多大?

直接判字符串一样输出-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) 收藏的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. POJ2061 Subsequence 2017-05-25 19:49 83人阅读 评论(0) 收藏

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14709   Accepted: 6210 Desc ...

  6. HDU6027 Easy Summation 2017-05-07 19:02 23人阅读 评论(0) 收藏

    Easy Summation                                                             Time Limit: 2000/1000 MS ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 手动更新花生壳域名的动态IP

    http://帐号:密码@ddns.oray.com/ph/update?hostname=hahaha.vicp.cc&myip=182.xx.200.xx 花生壳的文档地址 例子 1.使用 ...

  2. CenOS中的yum配置文件CentOS-Base.repo里面的参数都是何含义? souhu CentOS-Base.repo

    souhu  yum服务器CentOS-Base.repo 将$releasever替换为操作系统版本号 # CentOS-Base.repo # # The mirror system uses t ...

  3. ab压力测试之post与get请求

    安装ab工具 yum install httpd-tools 参数说明 -n:执行的请求个数,默认时执行一个请求 -c:一次产生的请求个数,即并发个数 -p:模拟post请求,文件格式为gid=2&a ...

  4. debian的甘特图工具

    sudo apt-get install planner

  5. ROS+nfdump 用户上网日志

    ROS 本身提供了 Traffic Flow 功能,与 Scisco的 Netflow 功能类似.只要开启 Traffic Flow 传到日志服务器即可, 这种设置系统开销很小,可以传到本地网络,也可 ...

  6. 给iOS开发新手送点福利,简述UISlide的属性和用法

    UISlide属性 1.   minimumValue  : 当值可以改变时,滑块可以滑动到最小位置的值,默认为0.0 _slider.minimumValue = 10.0; 2.   maximu ...

  7. django内置html模板的extends和include,模板标签{{ ex }}

    base.html内容 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  8. git/github基本命令

    Git与项目 git的使用,主要包括: 本地仓库的命令 远程仓库的命令 项目需求.页面.模型类的设计,及页面的使用 sudo apt-get install git 安装成功后,运行如下命令 git ...

  9. css字体中英文对照表(转)

     在css文件中,我们常看到有些字体名称变成了乱码,这是由于网页开发者将中文字体的名字直接写成了中文,而css文件本身没有声明字符编码方式,查看时就出现了乱码.为了避免这种乱码状况出现,可以将css文 ...

  10. C++Builder 也有StringBuilder

    System::Sysutils::TStringBuilder *sb = new TStringBuilder;    sb->Append("ww");    sb-& ...