#C5209. Software Version Control System
Software Version Control System
Software Version Control System
You are required to implement a software version control system. The system starts with an initial version identified as v0 - Initial version and supports the following operations:
- commit <message>: Save the current state with a commit message. The version increases sequentially (v1, v2, etc.).
- checkout <version>: Revert the system to a specified version, discarding all versions that came after it. If the version does not exist, the system should output an error message.
- list: Output all versions in chronological order (from v0 to the current version), each on a new line.
- log: Output all versions in reverse chronological order (from the current version down to v0), each on a new line.
All commands are read from standard input (stdin) and the outputs should be printed to standard output (stdout). If a checkout
command is issued with a non-existent version, output "Error: Version not found" and terminate further processing.
Note: If a checkout takes place, all commits made after the checked-out version are discarded. Ensure that your program processes commands in the given order.
inputFormat
The first line of input contains an integer n representing the number of commands. The next n lines each contain a command. The commands can be of the following types:
commit <message>
— Adds a new version with the commit message.checkout <version>
— Reverts to the specified version (e.g.,v1
).list
— Prints the list of all versions in chronological order.log
— Prints the version history in reverse order.
Commands are processed in the order they appear.
outputFormat
For each list
and log
command, output the respective version information with each version on a new line. If a checkout
command is issued for a non-existent version, output Error: Version not found
and stop processing further commands.
1
list
v0 - Initial version
</p>