DoubleString
SRM 690 · 2016-05-02 · by tozangezan
SRM 690 · 2016-05-02 · by tozangezan · String Manipulation
Problem Statement
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 aString 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.
You are given a
Constraints
- The length of S will be between 1 and 50, inclusive.
- Each character in S will be an uppercase letter ('A'-'Z').
Examples
0)
"MAZAIMAZAI" Returns: "square"
If T is "MAZAI", T+T will be "MAZAIMAZAI".
1)
"MAMAZAIZAI" Returns: "not square"
In this case, there is no string T for which T+T will be S.
2)
"IOI" Returns: "not square"
The length of S is odd, so it's impossible to make S by concatenating the same string twice.
3)
"AA" Returns: "square"
T will be "A".
4)
"ABCCBA" Returns: "not square"
Submissions are judged against all 43 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class DoubleString with a public method string check(string S) · 43 test cases · 2 s / 256 MB per case