TopcoderArchiveVisit Topcoder
SRM1 May 2015
SRM 658

InfiniteString

Problem statement, definition, constraints, and public examples.

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".

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

  1. "ab"
    "abab"
    Returns: "Equal"
    Both string will generate "ababababab...".
  2. "abc"
    "bca"
    Returns: "Not equal"
  3. "abab"
    "aba"
    Returns: "Not equal"
    The first one will generate "abababab...", but the second one will generate "abaaba...".
  4. "aaaaa"
    "aaaaaa"
    Returns: "Equal"
  5. "ababab"
    "abab"
    Returns: "Equal"
  6. "a"
    "z"
    Returns: "Not equal"
Back to all problems