0
点赞
收藏
分享

微信扫一扫

A. Mahmoud and Longest Uncommon Subsequence 字符串数组qwq

color_小浣熊 2022-06-29 阅读 18

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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
inputCopy
abcd
defgh
outputCopy
5
inputCopy
a
a
outputCopy
-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.
题意;查找最大公共子字符串的长度。
思路;string 处理,相同输出-1,不同输出长度最大的数。

#include <bits/stdc++.h>
#define ll long long
const int INF = 0x3f3f3f3f;
const ll LIMIT = 4294967295LL;
const ll maxn = -1;
const ll minn = 10000000010;
using namespace std;
string a,b;
int main() {
ll i, j;
ll maxn = -1;
ll minn = 10000000010;
ll n, m;
int t, t1;
cin >> a >> b;
if(a==b)
cout << "-1" << endl;
else cout << max(a.size(),b.size()) << endl;
return 0;
}
/*#include<bits/stdc++.h>
using namespace std;

string a,b;
int main()
{
cin>>a>>b;
if(a==b){
cout<<"-1"<<endl;
}else
cout<<max(a.size(),b.size())<<endl;
}
*/
///***Created by 软件我最菜 ***ACM******QWQ·***


举报

相关推荐

0 条评论