当马哈茂德和埃哈布为IOI做测试时,他们发现一个名叫最长公共子序列的问题。他们解决了这个问题,然后埃哈布用另一个问题挑战马哈茂德。
给定两个字符串a和b,找出它们最长的不公共子序列的长度,这是其中一个字符串的子序列而不是另一个的子序列的最长字符串。
某些字符串的子序列是以相同顺序出现在字符串中的字符序列,其出现不必连续,例如,字符串“ac”,“bc”,“abc”和“a”是字符串“abc”的子序列,而字符串“abbc”和“acb”则不是。空字符串是任何字符串的子序列。任何字符串都是其自身的子序列。
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.
Output
If there's no uncommon subsequence, print "
-1". Otherwise print the length of the longest uncommon subsequence of
a and
b.
Note
在第一个例子中:你可以从字符串 b 中选择“defgh”,因为它是字符串 b 的最长子序列,不会显示为字符串 a 的子序列。
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.