Dance

Time limit1sMemory limit128 MB

Summary
Check a sequence of dance steps against five textual rules and report which rules it violates, uppercasing any misplaced dip.
Level

Easy3 of 10

Topics
Implementation, String, Simulation
Solved
No attempts yet

Problem

Changyoung is learning to dance. A dance is a single line of steps separated by spaces, and it must follow these five rules.

  1. A dip may only be danced in one of these three situations:
    • immediately after a jiggle (e.g. ... jiggle dip ...)
    • two steps after a jiggle (e.g. ... jiggle stomp dip ...)
    • immediately before a twirl (e.g. ... dip twirl ...)
  2. Every dance must end with clap stomp clap.
  3. If twirl is danced at least once, then hop must be danced at least once as well.
  4. A dance may not start with jiggle.
  5. dip must be danced at least once.

Given the dance Changyoung performed, write a program that determines whether it obeys all of the rules.

Input

The input consists of several test cases. Each test case is a single line containing one dance. A dance has at most 1000 steps; each step consists of lowercase letters only and is at most 100 characters long. Input continues until end of file.

Output

Print one line for each test case.

  • If the dance obeys every rule, print form ok: followed by the dance exactly as given.
  • If the dance breaks exactly one rule, print form error K: followed by the dance, where K is the number of the broken rule.
  • If the dance breaks two or more rules, print form errors K(1), K(2), ..., K(N-1) and K(N): followed by the dance. The broken rule numbers K(i) are listed in ascending order.

When printing the dance, every dip that breaks rule 1 (danced in an invalid position) must be printed in uppercase as DIP.

Examples1

  1. Example 1

    Input
    dip twirl hop jiggle hop hop clap stomp clap
    dip hop jiggle hop hop clap stomp clap
    dip twirl hop jiggle hop hop clap clap stomp
    jiggle dip twirl hop jiggle hop hop clap stomp clap
    jiggle dip
    jiggle
    dip twirl hop dip jiggle hop dip hop clap stomp clap
    
    Expected output
    form ok: dip twirl hop jiggle hop hop clap stomp clap
    form error 1: DIP hop jiggle hop hop clap stomp clap
    form error 2: dip twirl hop jiggle hop hop clap clap stomp
    form error 4: jiggle dip twirl hop jiggle hop hop clap stomp clap
    form errors 2 and 4: jiggle dip
    form errors 2, 4 and 5: jiggle
    form error 1: dip twirl hop DIP jiggle hop dip hop clap stomp clap