In Romania, registration plates must be consist of exactly 3 distinct groups of letters and numbers, with each 2 consecutive groups being separated by one space character. Also, registration plates have some particular characteristics:
- First of all, the first character group can be either the character "B" (not "b") or any group of 2 capital letters from the English alphabet.
- The second group can only contain digits (0-9). Moreover, there must be exactly 2 digits in this group. The only exception is when the first group is B, in which case this group can contain either 2 or 3 digits.
- The last character group should always contain 3 capital letters, regardless of the values in the first 2 groups.
Being given some strings, you should output one of the messages Correct! or Incorrect! for each string, depending on whether or not the given string is a valid registration plate by the above rules.
Note: you will receive full feedback for this problem.
Input
The first line contains N, the number of registration plates to be validated.
Each of the following N lines contains a string of characters.
Output
For each registration plate, print on a separate line one of the messages Correct! or Incorrect!
Constraints
- 1 ≤ N ≤ 20
- Each of the strings representing registration plates can have between 0 and 20 characters.
Sample
Input | Output | Explanation |
---|---|---|
3 AB 12 ABC aB 1a Ca1 B 001 ERU | Correct! Incorrect! Correct! | The first registration plate is valid. The second registration plate is not valid, since none of the 3 groups respect the rules. The third registration plate is valid. |
This problem admits some very short solutions, based on regular expressions:
Sergiu Pușcaș - Python 3
1 #!/usr/bin/python3 2 import re 3 4 for _ in range(int(input())): 5 s = input() 6 print("Correct!" if re.match("[A-Z]{2}\s[0-9]{2}\s[A-Z]{3}", s) or \ 7 re.match("B\s[0-9]{2,3}\s[A-Z]{3}", s) else "Incorrect!")
Petru Trîmbițaș - Perl
1 use v5.16; 2 use warnings; 3 4 my $n = <>; 5 chomp $n; 6 for (1..$n) { 7 my $line = <>; 8 chomp $line; 9 if($line =~ /^(([A-Z][A-Z]\ [0-9]{2})|(B\ [0-9]{2,3}))\ [A-Z]{3}$/) { 10 say "Correct!"; 11 } else { 12 say "Incorrect!"; 13 } 14 }
Marius Gavrilescu - Perl
1 #!/usr/bin/perl 2 use v5.14; 3 use warnings; 4 <>; 5 say /^([A-Z][A-Z] \d\d|B \d{2,3}) [A-Z]{3}$/ ? 'Correct!' : 'Incorrect!' while <>;