#C5498. Data Synchronization Command Processor

    ID: 49153 Type: Default 1000ms 256MiB

Data Synchronization Command Processor

Data Synchronization Command Processor

Mike is developing a project to synchronize data between two systems. In this challenge, you are required to simulate a command processor that maintains an integer list. Initially, the list is empty. Your program must process a series of commands which modify the list. The commands are as follows:

  • add x: Append the integer \(x\) to the end of the list.
  • del x: Delete the first occurrence of the integer \(x\) from the list. If \(x\) is not present, ignore this command.
  • mod x y: Replace the first occurrence of integer \(x\) with integer \(y\) in the list. If \(x\) is not found, no modification is made.
  • rep: Output the current state of the list. The list is printed with elements separated by a single space. If the list is empty, print an empty line.

The goal is to process the given commands in order and produce the required outputs whenever a rep command is encountered.

Note: All inputs are provided via standard input and all outputs should be printed to standard output.

inputFormat

The first line of input contains an integer \(n\) representing the number of commands. The next \(n\) lines each contain one command, which can be one of the following formats:

  • add x
  • del x
  • mod x y
  • rep

outputFormat

For each occurrence of the rep command, output the current state of the list on a new line. The integers should be separated by a single space. If the list is empty at the time of a rep command, output an empty line.

## sample
10
add 4
add 2
add 7
rep
del 2
rep
mod 7 3
rep
del 5
rep
4 2 7

4 7 4 3 4 3

</p>