Problem Statement
Given a string s, let f(s) denote the infinite string obtained by concatenating infinitely many copies of s.
For example, if s = "abc" then f(s) = "abcabcabcabc...".
Note that the string f(s) still has a beginning. Hence, f("abc") and f("bca") are two different infinite strings: the first one starts with an 'a' while the other starts with a 'b'.
Sometimes, two different finite strings can produce the same infinite string. For example, f("abc") is the same as f("abcabc").
You are given Strings s and t. Check whether f(s) equals f(t). If the two infinite strings are equal, return "Equal". Otherwise, return "Not equal".
Note that the string f(s) still has a beginning. Hence, f("abc") and f("bca") are two different infinite strings: the first one starts with an 'a' while the other starts with a 'b'.
Sometimes, two different finite strings can produce the same infinite string. For example, f("abc") is the same as f("abcabc").
You are given Strings s and t. Check whether f(s) equals f(t). If the two infinite strings are equal, return "Equal". Otherwise, return "Not equal".
Definition
- Class:
- InfiniteString
- Method:
- equal
- Parameters:
- String, String
- Returns:
- String
- Method signature:
- String equal(String s, String t)
- (be sure your method is public)
Constraints
- s will contain between 1 and 50 elements, inclusive.
- t will contain between 1 and 50 elements, inclusive.
- Each character in s will be a lowercase English letter ('a'-'z').
- Each character in t will be a lowercase English letter ('a'-'z').
Examples
"ab"
"abab"
Returns: "Equal"
Both string will generate "ababababab..."."abc"
"bca"
Returns: "Not equal"
"abab"
"aba"
Returns: "Not equal"
The first one will generate "abababab...", but the second one will generate "abaaba..."."aaaaa"
"aaaaaa"
Returns: "Equal"
"ababab"
"abab"
Returns: "Equal"
"a"
"z"
Returns: "Not equal"