#C8639. Increment String Suffix
Increment String Suffix
Increment String Suffix
Given a string that may end with a sequence of digits, your task is to increment the numeric suffix by one. If the string does not end with digits, you should append 1
at the end.
If the string ends with a number, the incremented number should retain the same number of digits (i.e., preserve leading zeros). For example:
foobar23
becomesfoobar24
foo0041
becomesfoo0042
foo
becomesfoo1
- If the input is an empty string, output
1
.
Implement the solution using the standard input and output streams (stdin and stdout).
inputFormat
A single line string S (possibly empty) is provided via standard input.
outputFormat
Print the resulting string after incrementing the numeric suffix by one, or appending '1' if no numeric suffix exists, to standard output.## sample
foobar23
foobar24