#include <stdio.h>
// Define the structure to hold the totals for each county code
struct countryTotals {
int totalCorkCodes;
int totalDublinCodes;
int totalGalwayCodes;
int totalLimerickCodes;
int totalTiperaryCodes;
int totalWaterfordCodes;
int totalInvalidCountryCodes;
};
// Function prototype
struct countryTotals countCountyCodes(char countyCodes[], int size);
// Function definition
/**
* Function Name: countCountyCodes
*
* Function Block:
* Counts the occurrences of each valid Irish county code in the given array.
*
* @param countyCodes[] The array of characters containing county codes.
* @param size The size of the countyCodes array.
* @return A structure containing the total counts for each county code.
*/
struct countryTotals countCountyCodes(char countyCodes[], int size) {
struct countryTotals totals = {0, 0, 0, 0, 0, 0, 0}; // Initialize all counts to 0
for (int i = 0; i < size; i++) {
switch (countyCodes[i]) {
case 'C': case 'c':
totals.totalCorkCodes++;
break;
case 'D': case 'd':
totals.totalDublinCodes++;
break;
case 'G': case 'g':
totals.totalGalwayCodes++;
break;
case 'L': case 'l':
totals.totalLimerickCodes++;
break;
case 'T': case 't':
totals.totalTiperaryCodes++;
break;
case 'W': case 'w':
totals.totalWaterfordCodes++;
break;
default:
totals.totalInvalidCountryCodes++;
break;
}
}
return totals;
}
int main() {
char countyCodes[] = {'C', 'd', 'G', 'L', 't', 'W', 'X', 'c', 'D', 'g', 'l', 'T', 'w', 'Y'};
int size = sizeof(countyCodes) / sizeof(countyCodes[0]);
// Call the countCountyCodes function and get the result
struct countryTotals result = countCountyCodes(countyCodes, size);
// Print the results
printf("Cork Codes: %d\n", result.
totalCorkCodes); printf("Dublin Codes: %d\n", result.
totalDublinCodes); printf("Galway Codes: %d\n", result.
totalGalwayCodes); printf("Limerick Codes: %d\n", result.
totalLimerickCodes); printf("Tiperary Codes: %d\n", result.
totalTiperaryCodes); printf("Waterford Codes: %d\n", result.
totalWaterfordCodes); printf("Invalid Codes: %d\n", result.
totalInvalidCountryCodes);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgovLyBEZWZpbmUgdGhlIHN0cnVjdHVyZSB0byBob2xkIHRoZSB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CwgMCwgMCwgMCwgMH07IC8vIEluaXRpYWxpemUgYWxsIGNvdW50cyB0byAwCgogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBzaXplOyBpKyspIHsKICAgICAgICBzd2l0Y2ggKGNvdW50eUNvZGVzW2ldKSB7CiAgICAgICAgICAgIGNhc2UgJ0MnOiBjYXNlICdjJzoKICAgICAgICAgICAgICAgIHRvdGFscy50b3RhbENvcmtDb2RlcysrOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgJ0QnOiBjYXNlICdkJzoKICAgICAgICAgICAgICAgIHRvdGFscy50b3RhbER1YmxpbkNvZGVzKys7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgY2FzZSAnRyc6IGNhc2UgJ2cnOgogICAgICAgICAgICAgICAgdG90YWxzLnRvdGFsR2Fsd2F5Q29kZXMrKzsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlICdMJzogY2FzZSAnbCc6CiAgICAgICAgICAgICAgICB0b3RhbHMudG90YWxMaW1lcmlja0NvZGVzKys7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgY2FzZSAnVCc6IGNhc2UgJ3QnOgogICAgICAgICAgICAgICAgdG90YWxzLnRvdGFsVGlwZXJhcnlDb2RlcysrOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgJ1cnOiBjYXNlICd3JzoKICAgICAgICAgICAgICAgIHRvdGFscy50b3RhbFdhdGVyZm9yZENvZGVzKys7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICAgIHRvdGFscy50b3RhbEludmFsaWRDb3VudHJ5Q29kZXMrKzsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgIH0KCiAgICByZXR1cm4gdG90YWxzOwp9CgppbnQgbWFpbigpIHsKICAgIGNoYXIgY291bnR5Q29kZXNbXSA9IH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