fork download
  1. #include <stdio.h>
  2.  
  3. // Function prototype
  4. int validateIrishLicense(int year, int halfYear, char county, int sequenceNumber);
  5.  
  6. // Function definition
  7. /**
  8.  * Function Name: validateIrishLicense
  9.  *
  10.  * Function Block:
  11.  * Validates an Irish license plate based on the given parameters.
  12.  *
  13.  * @param year The two-digit year (13-24) representing 2013-2024.
  14.  * @param halfYear The half year indicator (1 for Jan-Jun, 2 for Jul-Dec).
  15.  * @param county The character representing the Irish county.
  16.  * @param sequenceNumber The sequence number (1 to 999999).
  17.  * @return 1 if the license plate is valid, otherwise 0.
  18.  */
  19. int validateIrishLicense(int year, int halfYear, char county, int sequenceNumber) {
  20. // Validate year
  21. if (year < 13 || year > 24) {
  22. return 0;
  23. }
  24.  
  25. // Validate half year
  26. if (halfYear != 1 && halfYear != 2) {
  27. return 0;
  28. }
  29.  
  30. // Validate county
  31. switch (county) {
  32. case 'C': case 'c':
  33. case 'D': case 'd':
  34. case 'G': case 'g':
  35. case 'L': case 'l':
  36. case 'T': case 't':
  37. case 'W': case 'w':
  38. break;
  39. default:
  40. return 0;
  41. }
  42.  
  43. // Validate sequence number
  44. if (sequenceNumber < 1 || sequenceNumber > 999999) {
  45. return 0;
  46. }
  47.  
  48. // All validations passed
  49. return 1;
  50. }
  51.  
  52. int main() {
  53. // Test cases
  54. int retVal1 = validateIrishLicense(13, 1, 'D', 21); // Valid
  55. int retVal2 = validateIrishLicense(13, 3, 'K', 1); // Invalid
  56. int retVal3 = validateIrishLicense(24, 1, 'C', 1245891); // Invalid
  57.  
  58. // Print results
  59. printf("Test case 1: %d\n", retVal1); // Expected output: 1
  60. printf("Test case 2: %d\n", retVal2); // Expected output: 0
  61. printf("Test case 3: %d\n", retVal3); // Expected output: 0
  62.  
  63. return 0;
  64. }
  65.  
Success #stdin #stdout 0s 5284KB
stdin
13,1 d, 21
stdout
Test case 1: 1
Test case 2: 0
Test case 3: 0