Practice
Product Code Format Check
2024/May/June·Variant 2·Q4·[6 marks]
MEDIUMValidation
A shop's product codes must pass three checks, in this order:
- The code is exactly 6 characters long.
- The first two characters are
SK. - The last four characters form an integer from 1000 to 9999 inclusive.
Keep reading a code until it passes all three checks. Output a specific error for the first check that fails, then output Accepted and the valid code.
Input: One or more product codes.
Output: An error line for each rejected code, then Accepted and the valid code.
Example:
Input: AB
SK12AB
SK1000
Output: Length must be 6
Last four must be 1000 to 9999
Accepted
SK1000
Sample Test Cases
Test 1: Already valid
Inputs: SK1000
Expected: Accepted
SK1000
Test 2: Length then digit-range errors
Inputs: AB, SK12AB, SK1000
Expected: Length must be 6
Last four must be 1000 to 9999
Accepted
SK1000