TopFox
SRM 584 · 2013-06-25 · by cgy4ever
SRM 584 · 2013-06-25 · by cgy4ever · Brute Force, String Manipulation
Problem Statement
Problem Statement
Fox Ciel is planning to register on TopFox. Her family name is familyName and her given name is givenName.
She will choose a TopFox handle according to the following rule. Let s be a non-empty prefix of her family name and let t be a non-empty prefix of her given name. Now Fox Ciel may choose the concatenation of s and t as her handle.
For example, suppose Fox Ciel's family name is "fox" and her given name is "ciel". She may choose the handle "foxciel", "fc", or "foxc". She may not choose "ox", "ciel", or "jiro".
You are told Fox Ciel's family name and given name. Return the number of possible handles Fox Ciel may choose.
She will choose a TopFox handle according to the following rule. Let s be a non-empty prefix of her family name and let t be a non-empty prefix of her given name. Now Fox Ciel may choose the concatenation of s and t as her handle.
For example, suppose Fox Ciel's family name is "fox" and her given name is "ciel". She may choose the handle "foxciel", "fc", or "foxc". She may not choose "ox", "ciel", or "jiro".
You are told Fox Ciel's family name and given name. Return the number of possible handles Fox Ciel may choose.
Constraints
- familyName will contain between 2 and 10 characters, inclusive.
- Each character in familyName will be a lowercase English letter, i.e., 'a'-'z'.
- givenName will contain between 2 and 10 characters, inclusive.
- Each character in givenName will be a lowercase English letter, i.e., 'a'-'z'.
Examples
0)
"ab" "cd" Returns: 4
There are 4 possible handles: "a" + "c" = "ac", "a" + "cd" = "acd", "ab" + "c" = "abc" and "ab" + "cd" = "abcd".
1)
"abb" "bbc" Returns: 7
There are 7 possible handles: "ab", "abb", "abbc", "abbb", "abbbc", "abbbb", "abbbbc".
2)
"fox" "ciel" Returns: 12
3)
"abbbb" "bbbbbbbc" Returns: 16
4)
"abxy" "xyxyxc" Returns: 21
Submissions are judged against all 61 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class TopFox with a public method int possibleHandles(string familyName, string givenName) · 61 test cases · 2 s / 256 MB per case