#C4584. Increment Versioned File Path
Increment Versioned File Path
Increment Versioned File Path
You are given a file system path as a string. The path may optionally end with a version number of the form _v<n>
, where n is a positive integer. Your task is to read a file path from stdin and output the file path with an incremented version number.
If the path ends with a version number, defined by the regular expression \(\_v\d+\), then its numeric part should be incremented by \(1\). Otherwise, append _v1
to the end of the string.
For example:
- If the input is
/user/documents/file
, then the output should be/user/documents/file_v1
. - If the input is
/user/music/song_v10
, then the output should be/user/music/song_v11
.
inputFormat
The input consists of a single line containing a string that represents the file path. The string is read from stdin.
outputFormat
Output the modified file path to stdout after applying the version number incrementing rule.
## sample/user/documents/file
/user/documents/file_v1