Check the String
Time limit2sMemory limit1024 MB
Given a string s of a and b and a list of stack commands (copy, swap, roll, fuse), report CRASH if a command fails, otherwise whether the final top string equals s.
- Level
Medium6 of 10
- Topics
- String, Simulation, Implementation
- Solved
- No attempts yet
Problem
Suppose we have a virtual machine that is described in the statement of problem B.
Given a string and a program of commands for this machine. Each command is one of copy, swap, roll, or fuse. Initially, the stack of the virtual machine contains two strings and looks like "a b". Execute all commands in the list in order.
Determine whether every command executed correctly or whether one of them caused a CRASH event. If every command executed correctly, also determine whether the string at the top of the stack after all commands have run is equal to .
Input
The first line contains the string . It consists only of the lowercase Latin letters a and b, and its length is between 1 and characters.
The second line contains an integer (). The next lines contain the commands, one per line, in the order they are executed. Each command is one of copy, swap, roll, or fuse.
Output
Print exactly one of the following messages.
CRASH: aCRASHevent occurred while the program ran.YES: after all commands run, the string at the top of the stack is equal to .NO: after all commands run, the string at the top of the stack is not equal to .