#include <stdio.h>
struct countyTotals{
int totalCorkCodes;
int totalDublinCodes;
int totalGalwayCodes;
int totalLimerickCodes;
int totalTiperaryCodes;
int totalWaterfordCodes;
int totalInvalidCountyCodes;
};
struct countyTotals countCntyOccur (char cntyCodes[], int size);
int main(void) {
char cntyCodes[]= {'C','c','c','D','d','G','L','l','l','L','T','t','t','W','w','X'};
struct countyTotals countyFreqs = countCntyOccur(cntyCodes,16);
printf("Cork County: %i\n", countyFreqs.
totalCorkCodes); printf("Dublin County: %i\n", countyFreqs.
totalDublinCodes); printf("Galway County: %i\n", countyFreqs.
totalGalwayCodes); printf("Limerick County: %i\n", countyFreqs.
totalLimerickCodes); printf("Tiperary County: %i\n", countyFreqs.
totalTiperaryCodes); printf("Waterford County: %i\n", countyFreqs.
totalWaterfordCodes); printf("InvalidCountyCodes: %i\n", countyFreqs.
totalInvalidCountyCodes);
return 0;
}
struct countyTotals countCntyOccur(char cntyCodes[], int size){
int totalCorkCodes=0;
int totalDublinCodes=0;
int totalGalwayCodes=0;
int totalLimerickCodes=0;
int totalTiperaryCodes=0;
int totalWaterfordCodes=0;
int totalInvalidCountyCodes=0;
for (int i = 0; i < size; i++) {
// Switch statement
switch (cntyCodes[i]) {
case 'C':
case 'c':
totalCorkCodes+=1;
break;
case 'D':
case 'd':
totalDublinCodes+=1;
break;
case 'G':
case 'g':
totalGalwayCodes+=1;
break;
case 'L':
case 'l':
totalLimerickCodes+=1;
break;
case 'T':
case 't':
totalTiperaryCodes+=1;
break;
case 'W':
case 'w':
totalWaterfordCodes+=1;
break;
default:
totalInvalidCountyCodes+=1;
break;
}
}
struct countyTotals specificCountyTotals = {totalCorkCodes, totalDublinCodes, totalGalwayCodes,
totalLimerickCodes, totalTiperaryCodes,
totalWaterfordCodes, totalInvalidCountyCodes};
return specificCountyTotals;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgpzdHJ1Y3QgY291bnR5VG90YWxzewogICAgICAgIGludCB0b3RhbENvcmtDb2RlczsKICAgICAg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JJbnZhbGlkQ291bnR5Q29kZXM6ICVpXG4iLCBjb3VudHlGcmVxcy50b3RhbEludmFsaWRDb3VudHlDb2Rlcyk7CgoJcmV0dXJuIDA7Cn0KCgpzdHJ1Y3QgY291bnR5VG90YWxzIGNvdW50Q250eU9jY3VyKGNoYXIgY250eUNvZGVzW10sIGludCBzaXplKXsKCiAgICBpbnQgdG90YWxDb3JrQ29kZXM9MDsKICAgIGludCB0b3RhbER1YmxpbkNvZGVzPTA7CiAgICBpbnQgdG90YWxHYWx3YXlDb2Rlcz0wOwogICAgaW50IHRvdGFsTGltZXJpY2tDb2Rlcz0wOwogICAgaW50IHRvdGFsVGlwZXJhcnlDb2Rlcz0wOwogICAgaW50IHRvdGFsV2F0ZXJmb3JkQ29kZXM9MDsKICAgIGludCB0b3RhbEludmFsaWRDb3VudHlDb2Rlcz0wOwoKCiAgICBmb3IgKGludCBpID0gMDsgaSA8IHNpemU7IGkrKykgewogICAgICAgIC8vIFN3aXRjaCBzdGF0ZW1lbnQKICAgICAgICBzd2l0Y2ggKGNudHlDb2Rlc1tpXSkgewogICAgICAgIGNhc2UgJ0MnOgogICAgICAgIGNhc2UgJ2MnOgogICAgICAgICAgICB0b3RhbENvcmtDb2Rlcys9MTsKICAgICAgICAgICAgYnJlYWs7CgogICAgICAgIGNhc2UgJ0QnOgogICAgICAgIGNhc2UgJ2QnOgogICAgICAgICAgICB0b3RhbER1YmxpbkNvZGVzKz0xOwogICAgICAgICAgICBicmVhazsKCiAgICAgICAgY2FzZSAnRyc6CiAgICAgICAgY2FzZSAnZyc6CiAgICAgICAgICAgIHRvdGFsR2Fsd2F5Q29kZXMrPTE7CiAgICAgICAgICAgIGJyZWFrOwoKICAgICAgICBjYXNlICdMJzoKICAgICAgICBjYXNlICdsJzoKICAgICAgICAgICAgdG90YWxMaW1lcmlja0NvZGVzKz0xOwogICAgICAgICAgICBicmVhazsKICAgICAgICAKICAgICAgICBjYXNlICdUJzoKICAgICAgICBjYXNlICd0JzoKICAgICAgICAgICAgdG90YWxUaXBlcmFyeUNvZGVzKz0xOwogICAgICAgICAgICBicmVhazsKICAgICAgICAKICAgICAgICBjYXNlICdXJzoKICAgICAgICBjYXNlICd3JzoKICAgICAgICAgICAgdG90YWxXYXRlcmZvcmRDb2Rlcys9MTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgCiAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgdG90YWxJbnZhbGlkQ291bnR5Q29kZXMrPTE7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KCiAgICB9CgogICAgc3RydWN0IGNvdW50eVRvdGFscyBzcGVjaWZpY0NvdW50eVRvdGFscyA9IHt0b3RhbENvcmtDb2RlcywgdG90YWxEdWJsaW5Db2RlcywgdG90YWxHYWx3YXlDb2RlcywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdG90YWxMaW1lcmlja0NvZGVzLCB0b3RhbFRpcGVyYXJ5Q29kZXMsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRvdGFsV2F0ZXJmb3JkQ29kZXMsIHRvdGFsSW52YWxpZENvdW50eUNvZGVzfTsKICAgIAogICAgcmV0dXJuIHNwZWNpZmljQ291bnR5VG90YWxzOwoKfQ==