2018-4-15-BNUZ-ACM-GDCPC选拔赛 D

D - Mahmoud and Longest Uncommon Subsequence

 

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 <bits/stdc++.h>
using namespace std;
int main(){
	char a[100005],b[100005];
	gets(a);gets(b);
	if(strcmp(a,b)==0) printf("-1\n");
	else if(strlen(a)>strlen(b))
	printf("%d\n",strlen(a));
	else 
	printf("%d\n",strlen(b));
}

思考,疑问:这个要怎么改

#include <bits/stdc++.h>
using namespace std;
int main(){
	char a[100005],b[100005];
	gets(a);gets(b);
	if(!strcmp(a,b)) printf("-1\n");
	else printf("%d\n",strcmp(a,b)>0 ? strlen(a):strlen(b));
}

阅读更多
文章标签: 字符串
个人分类: 训练赛补题
想对作者说点什么? 我来说一句

2010ACM选拔赛2010ACM选拔赛

2010年06月28日 25KB 下载

没有更多推荐了,返回首页

不良信息举报

2018-4-15-BNUZ-ACM-GDCPC选拔赛 D

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭