Three-Tier Chocolate Ice Cream
InterviewTime limit1sMemory limit1024 MB
Given uppercase strings, decide whether each one matches one of four three-part patterns built from a prefix of length ceil(n/3) and its reverse.
- Level
Easy2 of 10
- Topics
- Implementation, String, Brute force
- Solved
- No attempts yet
Problem
Coco likes to stack chocolate ice cream scoops and eat them. A stack of chocolate ice cream can be written as a string of uppercase English letters. For example, a stack of Belgian, mint, and original flavors, from bottom to top, can be written as BMO.
Coco defined a "two-tier ice cream" as follows.
- Given an ice cream string of length , consider the prefix of with length . is the smallest integer greater than or equal to .
- is a two-tier ice cream if or . Here is the concatenation of and in that order, is with its characters in reverse order, and is with its first character removed.
Disappointed that this definition is the same as the ordinary definition of a palindrome, Coco defined a further step, the "three-tier ice cream."
- Given an ice cream string of length , consider the prefix of with length .
- is a three-tier ice cream if at least one of the following holds.
For example, DOTTODOT = DOT + TOD + OT, so it is a three-tier ice cream.
Determine whether each given string is a three-tier ice cream string.
Input
The first line contains the number of test cases . ()
Each of the next lines contains a string of uppercase English letters. The length of each string is at least and at most .
Output
For each test case, print 1 if the given string is a three-tier ice cream string, and 0 otherwise.