#K49737. Next Project Identifier
Next Project Identifier
Next Project Identifier
You are given a project identifier that consists of a capital letter followed by a three-digit number. The letter is one of the sequence: \(P, Q, R, S\) and the number ranges from 000 to 999. Your task is to produce the next identifier according to the following rules:
- If the numeric part is less than 999, simply increment the number (keeping three digits with leading zeros).
- If the numeric part is 999, then reset the numeric part to 000 and move to the next letter in the sequence. The sequence cycles, meaning that after \(S\) comes \(P\).
For example:
- Input:
P001
→ Output:P002
- Input:
P999
→ Output:Q000
- Input:
S999
→ Output:P000
The formula for checking when to change the letter is when \(n + 1 > 999\), where \(n\) is the current number. The new identifier is then formed as:
[ \text{new_identifier} = \text{next_letter} ; + ; \text{formatted number} ]
Ensure that your solution reads input from stdin
and writes output to stdout
.
inputFormat
The input is a single line containing the current project identifier as a string. For example, P001
.
outputFormat
The output is a single line containing the next project identifier following the described rules. For example, P002
.
P001
P002
</p>