#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', 'E', 'G', 'G', 'L', 'l', 'l', 'T', 'W', 'J', 'd'};
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+CgpzdHJ1Y3QgY291bnR5VG90YWxzewogICAgICAgIGludCB0b3RhbENvcmtDb2RlczsKICAgICAgICBpbnQgdG90YWxEdWJsaW5Db2RlczsKICAgICAgICBpbnQgdG90YWxHYWx3YXlDb2RlczsKICAgICAgICBpbnQgdG90YWxMaW1lcmlja0NvZGVzOwogICAgICAgIGludCB0b3RhbFRpcGVyYXJ5Q29kZXM7CiAgICAgICAgaW50IHRvdGFsV2F0ZXJmb3JkQ29kZXM7CiAgICAgICAgaW50IHRvdGFsSW52YWxpZENvdW50eUNvZGVzOyAgIAp9OwoKc3RydWN0IGNvdW50eVRvdGFscyBjb3VudENudHlPY2N1ciAoY2hhciBjbnR5Q29kZXNbXSwgaW50IHNpemUpOwoKaW50IG1haW4odm9pZCkgewoKCWNoYXIgY250eUNvZGVzW109IHsnQycsICdjJywgJ0UnLCAnRycsICdHJywgJ0wnLCAnbCcsICdsJywgJ1QnLCAnVycsICdKJywgJ2QnfTsKICAgIHN0cnVjdCBjb3VudHlUb3RhbHMgY291bnR5RnJlcXMgPSBjb3VudENudHlPY2N1cihjbnR5Q29kZXMsMTYpOwogICAgcHJpbnRmKCJDb3JrIENvdW50eTogJWlcbiIsIGNvdW50eUZyZXFzLnRvdGFsQ29ya0NvZGVzKTsKICAgIHByaW50ZigiRHVibGluIENvdW50eTogJWlcbiIsIGNvdW50eUZyZXFzLnRvdGFsRHVibGluQ29kZXMpOwogICAgcHJpbnRmKCJHYWx3YXkgQ291bnR5OiAlaVxuIiwgY291bnR5RnJlcXMudG90YWxHYWx3YXlDb2Rlcyk7CiAgICBwcmludGYoIkxpbWVyaWNrIENvdW50eTogJWlcbiIsIGNvdW50eUZyZXFzLnRvdGFsTGltZXJpY2tDb2Rlcyk7CiAgICBwcmludGYoIlRpcGVyYXJ5IENvdW50eTogJWlcbiIsIGNvdW50eUZyZXFzLnRvdGFsVGlwZXJhcnlDb2Rlcyk7CiAgICBwcmludGYoIldhdGVyZm9yZCBDb3VudHk6ICVpXG4iLCBjb3VudHlGcmVxcy50b3RhbFdhdGVyZm9yZENvZGVzKTsKICAgIHByaW50ZigiSW52YWxpZENvdW50eUNvZGVzOiAlaVxuIiwgY291bnR5RnJlcXMudG90YWxJbnZhbGlkQ291bnR5Q29kZXMpOwoKCXJldHVybiAwOwp9CgoKc3RydWN0IGNvdW50eVRvdGFscyBjb3VudENudHlPY2N1cihjaGFyIGNudHlDb2Rlc1tdLCBpbnQgc2l6ZSl7CgogICAgaW50IHRvdGFsQ29ya0NvZGVzPTA7CiAgICBpbnQgdG90YWxEdWJsaW5Db2Rlcz0wOwogICAgaW50IHRvdGFsR2Fsd2F5Q29kZXM9MDsKICAgIGludCB0b3RhbExpbWVyaWNrQ29kZXM9MDsKICAgIGludCB0b3RhbFRpcGVyYXJ5Q29kZXM9MDsKICAgIGludCB0b3RhbFdhdGVyZm9yZENvZGVzPTA7CiAgICBpbnQgdG90YWxJbnZhbGlkQ291bnR5Q29kZXM9MDsKCgogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBzaXplOyBpKyspIHsKICAgICAgICAvLyBTd2l0Y2ggc3RhdGVtZW50CiAgICAgICAgc3dpdGNoIChjbnR5Q29kZXNbaV0pIHsKICAgICAgICBjYXNlICdDJzoKICAgICAgICBjYXNlICdjJzoKICAgICAgICAgICAgdG90YWxDb3JrQ29kZXMrPTE7CiAgICAgICAgICAgIGJyZWFrOwoKICAgICAgICBjYXNlICdEJzoKICAgICAgICBjYXNlICdkJzoKICAgICAgICAgICAgdG90YWxEdWJsaW5Db2Rlcys9MTsKICAgICAgICAgICAgYnJlYWs7CgogICAgICAgIGNhc2UgJ0cnOgogICAgICAgIGNhc2UgJ2cnOgogICAgICAgICAgICB0b3RhbEdhbHdheUNvZGVzKz0xOwogICAgICAgICAgICBicmVhazsKCiAgICAgICAgY2FzZSAnTCc6CiAgICAgICAgY2FzZSAnbCc6CiAgICAgICAgICAgIHRvdGFsTGltZXJpY2tDb2Rlcys9MTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgCiAgICAgICAgY2FzZSAnVCc6CiAgICAgICAgY2FzZSAndCc6CiAgICAgICAgICAgIHRvdGFsVGlwZXJhcnlDb2Rlcys9MTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgCiAgICAgICAgY2FzZSAnVyc6CiAgICAgICAgY2FzZSAndyc6CiAgICAgICAgICAgIHRvdGFsV2F0ZXJmb3JkQ29kZXMrPTE7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIAogICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgIHRvdGFsSW52YWxpZENvdW50eUNvZGVzKz0xOwogICAgICAgICAgICBicmVhazsKICAgICAgICB9CgogICAgfQoKICAgIHN0cnVjdCBjb3VudHlUb3RhbHMgc3BlY2lmaWNDb3VudHlUb3RhbHMgPSB7dG90YWxDb3JrQ29kZXMsIHRvdGFsRHVibGluQ29kZXMsIHRvdGFsR2Fsd2F5Q29kZXMsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRvdGFsTGltZXJpY2tDb2RlcywgdG90YWxUaXBlcmFyeUNvZGVzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0b3RhbFdhdGVyZm9yZENvZGVzLCB0b3RhbEludmFsaWRDb3VudHlDb2Rlc307CiAgICAKICAgIHJldHVybiBzcGVjaWZpY0NvdW50eVRvdGFsczsKCn0=