printРабочее место участника

printЗадачи

1511. Slurpys

Ограничения: время – 1s/2s, память – 32MiB Ввод: input.txt или стандартный ввод Вывод: output.txt или стандартный вывод copy
Послать решение Blockly Посылки Темы Где Обсудить (0)

14179.jpg
r. Zoidberg is a ET.
A Slurpy is a word in his language that has certain properties.
Your program will read in strings of characters and output whether or not they are Slurpys.

A Slump is a character string that has the following properties:
  • Its first character is either a 'D' or an 'E'.
  • The first character is followed by a string of one or more 'F's.
  • The string of one or more 'F's is followed by either a Slump or a 'G'. The Slump or 'G' that follows the F's ends the Slump. For example 'DFFEFFFG' is a Slump since it has a 'D' for its first character, followed by a string of two 'F's, and ended by the Slump 'EFFFG'.
  • Nothing else is a Slump.
A Slimp is a character string that has the following properties:
  • Its first character is an 'A'.
  • If it is a two character Slimp then its second and last character is an 'H'.
  • If it is not a two character Slimp then it is in one of these two forms:
    a) 'A' followed by 'B' followed by a Slimp followed by a 'C'.
    b) 'A' followed by a Slump (see above) followed by a 'C'.
  • Nothing else is a Slimp.
A Slurpy is a word that consists of a Slimp followed by a Slump.
Examples
Slumps: DFG, EFG, DFFFFFG, DFDFDFDFG, DFEFFFFFG
Not Slumps: DFEFF, EFAHG, DEFG, DG, EFFFFDG
Slimps: AH, ABAHC, ABABAHCC, ADFGC, ADFFFFGC, ABAEFGCC, ADFDFGC
Not Slimps: ABC, ABAH, DFGC, ABABAHC, SLIMP, ADGC
Slurpys: AHDFG, ADFGCDFFFFFG, ABAEFGCCDFEFFFFFG
Not Slurpys: AHDFGA, DFGAH, ABABCC
The first line of input contains an integer `N` between 1 and 10 describing how many strings of characters are represented. The next `N` lines each contain a string of 1 to 60 alpha characters.
Each of `N` lines of output should consist of either YES or NO depending on whether or not the corresponding input line is a Slurpy.

Input Sample

2
AHDFG
DFGAH

Output Sample

YES
NO
loading