#include <stdio.h>
int irishLicensePlateValidator(int year, int halfYear, char county, int snumber);
int main(void) {
printf("%i", irishLicensePlateValidator
(19, 1, 'c', 124596));
return 0;
}
int irishLicensePlateValidator(int year, int halfYear, char county, int snumber)
{
char validcounties[] = {'c', 'C', 'd', 'D', 'g', 'G', 'l', 'L', 't', 'T', 'w', 'W'}; // array of valid county abbreviations
int i; // loop index
// varying conditions that test validity
// if any of the conditions are met, the code stops and returns a 0 to indicate the plate is not valid
// if none of the conditions is meet, the code goes all the way through and returns a 1 to indicate the plate is valid
// checks to see if the year is between 13 and 24
if (year < 13)
{
return 0;
}
if (year > 24)
{
return 0;
}
// checks to see if the halfyear period is 1.
// if not, checks to see if it is 2
if (halfYear != 1)
{
if (halfYear != 2)
{
return 0;
}
}
// loop to check the char vs the validcounties array
for (i = 0; i < 12;)
{
if (validcounties[i] == county)
{
i = 12;
}
if (validcounties[i] != county)
{
i++;
}
if (i == 12)
{
return 0;
}
}
// since the maximum is 6 digits, the number cannot be higher than 999999
// since there are no leading zeroes the smallest number can only be 100000
if (snumber > 999999)
{
return 0;
}
if (snumber < 100000)
{
return 0;
}
return 1;
} //irishLicensePlateValidator
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgaXJpc2hMaWNlbnNlUGxhdGVWYWxpZGF0b3IoaW50IHllYXIsIGludCBoYWxmWWVhciwgY2hhciBjb3VudHksIGludCBzbnVtYmVyKTsKCmludCBtYWluKHZvaWQpIHsKCXByaW50ZigiJWkiLCBpcmlzaExpY2Vuc2VQbGF0ZVZhbGlkYXRvciAoMTksIDEsICdjJywgMTI0NTk2KSk7CgoJcmV0dXJuIDA7Cn0KCmludCBpcmlzaExpY2Vuc2VQbGF0ZVZhbGlkYXRvcihpbnQgeWVhciwgaW50IGhhbGZZZWFyLCBjaGFyIGNvdW50eSwgaW50IHNudW1iZXIpCnsKCWNoYXIgdmFsaWRjb3VudGllc1tdID0geydjJywgJ0MnLCAnZCcsICdEJywgJ2cnLCAnRycsICdsJywg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