TopcoderArchiveVisit Topcoder
SRM2 May 2016
SRM 690

DoubleString

Problem statement, definition, constraints, and public examples.

Problem Statement

A string is called a square if it can be created by concatenating two copies of the same string. For example, "CANCAN" is a square because it consists of two copies of the string "CAN". Other squares include "AA", "ZZZZ", and "BERIBERI". The strings "AAAAA" and "HAHAHA" are not squares.

You are given a String S. Return "square" (quotes for clarity) if there is a string T such that S = T + T. Otherwise, return "not square". Note that the return value is case-sensitive.

Definition

Class:
DoubleString
Method:
check
Parameters:
String
Returns:
String
Method signature:
String check(String S)
(be sure your method is public)

Constraints

  • The length of S will be between 1 and 50, inclusive.
  • Each character in S will be an uppercase letter ('A'-'Z').

Examples

  1. "MAZAIMAZAI"
    Returns: "square"
    If T is "MAZAI", T+T will be "MAZAIMAZAI".
  2. "MAMAZAIZAI"
    Returns: "not square"
    In this case, there is no string T for which T+T will be S.
  3. "IOI"
    Returns: "not square"
    The length of S is odd, so it's impossible to make S by concatenating the same string twice.
  4. "AA"
    Returns: "square"
    T will be "A".
  5. "ABCCBA"
    Returns: "not square"
  6. "Y"
    Returns: "not square"
Back to all problems