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 ...
随机推荐
- 转:HL7 Tools suite
HL7 Tools suite HL7的官网有很多开源工具, 比如:RoseTree,V3Generator,RMIM Designer, Design Repository, V2 & ...
- VS2010 C++环境下DLL和LIB文件的生成与调试 备忘
利用VS2010工具,调试DLL文件的方法现总结如下: 在一个解决方案中生成两个工程,假设MYDLL和MYDLG两个工程,前者是DLL工程,后者DLG调用前边的DLL工程.设置如下: 目录如下:图,本 ...
- GIT的安装及上传代码到码云
前言 昨天初次接触GIT及码云,虽然用了2个多小时才搞定,但是还是挺开心的.码云是一个可以储存我们写的代码的一个平台,而Git是一款免费.开源的分布式版本控制系统,可以敏捷高效地处理任何或小或大的项目 ...
- request 里面参数设置 (有空瞄下)
Requests 是用python语言编写的第三方库,基于 urllib,采用 Apache2 Licensed 开源协议的 HTTP 库.它比 urllib 更加方便,完全满足 HTTP 测试需求, ...
- [置顶]
caffe+CPU︱虚拟机+Ubuntu16.04+CPU+caffe安装笔记
由于虚拟机下的Ubuntu系统一般不包含GPU,故这次安装时为了在无GUP环境下运行caffe.所以只需安装CPU版本的caffe 由于本机是window10系统,所以想尝试caffe就在自己电脑上整 ...
- MySQL 5.7 免安装版配置
MySQL5.7免安装版配置 Mysql是一个比较流行且很好用的一款数据库软件,如下记录了我学习总结的mysql免安装版的配置经验. 一. 软件下载 5.7 32位https://dev.mysq ...
- ArrayList实现
数组实现父类:AbstractList接口:List,RandomAccess,Cloneable,Serializable字段://默认容量private static final int DEFA ...
- Mathtype 公式显示方框
公式编辑器mathtype中一些符号显示方框,如何解决呢?出现这个问题的原因是这是因为windows中的mtextra.ttf(显示为MT Extra (TrueType))字体文件不存在或版本太低, ...
- Mock.js开发中拦截Ajax
Mock.js 是一款前端开发中拦截Ajax请求再生成随机数据响应的工具.可以用来模拟服务器响应. 优点是非常简单方便, 无侵入性, 基本覆盖常用的接口数据类型. 在我们的生产实际中,后端的接口往往是 ...
- 行为型-命令模式(Command)
装修新房的最后几道工序之一是安装插座和开关,通过开关可以控制一些电器的打开和关闭,例如电灯或者排气扇.在购买开关时,我们并不知道它将来到底用于控制什么电器,也就是说,开关与电灯.排气扇并无直接关系,一 ...