fork download
  1.  
  2. #include <stdio.h>
  3.  
  4. /*
  5.  * Irish License Plate Validator (2013–2024)
  6.  * Returns 1 if valid, 0 if invalid.
  7.  *
  8.  * Rules:
  9.  * - year: 13..24
  10.  * - halfYear: 1 or 2
  11.  * - county: C/D/G/L/T/W (upper or lower)
  12.  * - sequence: 1..999999 (1 to 6 digits, no leading zeros implied by integer)
  13.  */
  14. int irishLicensePlateValidator(int year, int halfYear, char county, int sequence)
  15. {
  16. if (year < 13 || year > 24)
  17. return 0;
  18.  
  19. if (halfYear != 1 && halfYear != 2)
  20. return 0;
  21.  
  22. switch (county)
  23. {
  24. case 'C': case 'c':
  25. case 'D': case 'd':
  26. case 'G': case 'g':
  27. case 'L': case 'l':
  28. case 'T': case 't':
  29. case 'W': case 'w':
  30. break; /* valid county */
  31. default:
  32. return 0; /* invalid county */
  33. }
  34.  
  35. if (sequence < 1 || sequence > 999999)
  36. return 0;
  37.  
  38. return 1;
  39. }
  40.  
  41. int main(void)
  42. {
  43. int retVal;
  44.  
  45. /* Valid example from prompt */
  46. retVal = irishLicensePlateValidator(13, 1, 'D', 21);
  47. printf("Test 1: (13, 1, 'D', 21) -> %s\n", retVal ? "VALID" : "INVALID");
  48.  
  49. /* Invalid example: bad half year and county */
  50. retVal = irishLicensePlateValidator(13, 3, 'K', 1);
  51. printf("Test 2: (13, 3, 'K', 1) -> %s\n", retVal ? "VALID" : "INVALID");
  52.  
  53. /* Invalid example: sequence too large */
  54. retVal = irishLicensePlateValidator(24, 1, 'C', 1245891);
  55. printf("Test 3: (24, 1, 'C', 1245891) -> %s\n", retVal ? "VALID" : "INVALID");
  56.  
  57. /* A couple extra quick checks */
  58. retVal = irishLicensePlateValidator(14, 2, 'g', 999999);
  59. printf("Test 4: (14, 2, 'g', 999999) -> %s\n", retVal ? "VALID" : "INVALID");
  60.  
  61. retVal = irishLicensePlateValidator(12, 1, 'D', 21);
  62. printf("Test 5: (12, 1, 'D', 21) -> %s\n", retVal ? "VALID" : "INVALID");
  63.  
  64. return 0;
  65. }
  66.  
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
Test 1: (13, 1, 'D', 21) -> VALID
Test 2: (13, 3, 'K', 1)  -> INVALID
Test 3: (24, 1, 'C', 1245891) -> INVALID
Test 4: (14, 2, 'g', 999999) -> VALID
Test 5: (12, 1, 'D', 21) -> INVALID