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. 简单遗传算法-python实现

    ObjFunction.py import math def GrieFunc(vardim, x, bound): """ Griewangk function &qu ...

  2. 今日头条、抖音、西瓜、火山、微视、陌陌等自媒体平台小视频批量下载工具v1.1.0(视频搬运福利)

    前言 目前各大自媒体平台爆火,网络流量暴涨,各大自媒体平台的小视频为广大个广告主带来了如泉涌般的的视频流量,更给广大的自媒体小编带来了丰厚的利益回报,想要创做更多的自媒体内容着实不易,下面给广大的小视 ...

  3. eclipse 和 Myeclipse中Maven Web项目出现小红叉的 详细解决方法

    在我们创建maven项目是常会出现小红叉,如图: 解决办法: 1.可以 点击鼠标右键  maven--->update project.一般可以解决. 2.查看 window---->sh ...

  4. 使用anaconda安装tensorflow (windows10环境)

    版权声明:勤学 修德 明辨 笃实 - CSDN周雄伟 https://blog.csdn.net/ebzxw/article/details/80701613 已有环境:python3.7.1 ana ...

  5. Poly

    folly/Poly.h Poly is a class template that makes it relatively easy to define a type-erasing polymor ...

  6. Spring集成的Quartz 并发

    以前经常在任务调度程序中使用Spring集成的Quartz,这种方式可以用简单的声明式配置即可实现定时任务,并结合了Spring自身的Bean的管理功能,非常方便.配置样本如下: <bean i ...

  7. 跟我学算法-opencv加载,修改,保存

    #include<opencv2/opencv.hpp> #include<iostream> #include<math.h> using namespace c ...

  8. dsm winscp 获得 root 权限修改上传文件

    使用DSM开了ssh只可以用admin登陆scp没有权限上传文件.可以用以下方法. ssh 登陆 dsm sudo -i  取得root权限 修改 /etc/sudoers 文件中 %administ ...

  9. maven 中的依赖

  10. google-gson库下的gson的基本使用

    public class Users { private String username; private String password; private Integer age; public S ...