#include <stdio.h>
struct countyTotals{
int totalCorkCodes;
int totalDublinCodes;
int totalGalwayCodes;
int totalLimerickCodes;
int totalTiperaryCodes;
int totalWaterfordCodes;
int totalInvalidCountyCodes;
};
struct countyTotals freqOfIrishCounties (char cntyCodes[], int size);
int main(void) {
char countyArrayList[]= {'C', 'c', 'E', 'G', 'G', 'L', 'l', 'l', 'T', 'W', 'J', 'd'};
struct countyTotals countyFreqs = freqOfIrishCounties(countyArrayList,12);
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;
}
//**************************************************************
// Function: freqOfIrishCounties
//
// Purpose: Count the total number of occurrences of each county code
//
// Parameters:
//
// countyArrayList - character array that holds the list of county codes
// size - the number of elements in the cntyCodes array
//
// Returns: a structure that holds the total number of occurrences of each county code
//
//**************************************************************
struct countyTotals freqOfIrishCounties(char countyArrayList[], int size){
struct countyTotals myCountyTotals = {0,0,0,0,0,0,0}; // holds the country counts
// and initializes them to zero
for (int i = 0; i < size; i++) {
switch (countyArrayList[i]) { /*looping through the county codes in the list and using the cntycode as the basis for the switch statement */
case 'C':
case 'c':
myCountyTotals.totalCorkCodes++; /* if the cnty code is 'C' or 'c', then incrementing the count associated with total Cork county codes*/
break;
case 'D':
case 'd':
myCountyTotals.totalDublinCodes+=1; /*same logic as mentioned in the previous comment, but for a different county, with different abbreviations*/
break;
case 'G':
case 'g':
myCountyTotals.totalGalwayCodes+=1;
break;
case 'L':
case 'l':
myCountyTotals.totalLimerickCodes+=1;
break;
case 'T':
case 't':
myCountyTotals.totalTiperaryCodes+=1;
break;
case 'W':
case 'w':
myCountyTotals.totalWaterfordCodes+=1;
break;
default:
myCountyTotals.totalInvalidCountyCodes+=1; /*if none of the other conditions were met, this is an invalid county code and the variable
holding the total occurrences of invalid county codes should be incremented by 1 */
break;
}
}
return myCountyTotals;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgpzdHJ1Y3QgY291bnR5VG90YWxzewogICAgICAgIGludCB0b3RhbENvcmtDb2RlczsKICAgICAgICBpbnQgdG90YWxEdWJsaW5Db2RlczsKICAgICAgICBpbnQgdG90YWxHYWx3YXlDb2RlczsKICAgICAgICBpbnQgdG90YWxMaW1lcmlja0NvZGVzOwogICAgICAgIGludCB0b3RhbFRpcGVyYXJ5Q29kZXM7CiAgICAgICAgaW50IHRvdGFsV2F0ZXJmb3JkQ29kZXM7CiAgICAgICAgaW50IHRvdGFsSW52YWxpZENvdW50eUNvZGVzOyAgIAp9OwoKc3RydWN0IGNvdW50eVRvdGFscyBmcmVxT2ZJcmlzaENvdW50aWVzIChjaGFyIGNudHlDb2Rlc1tdLCBpbnQgc2l6ZSk7CgppbnQgbWFpbih2b2lkKSB7CgoJY2hhciBjb3VudHlBcnJheUxpc3RbXT0geydDJywgJ2MnLCAnRScsICdHJywgJ0cnLCAnTCcsICdsJywgJ2wnLCAnVCcsICdXJywgJ0onLCAnZCd9OwogICAgc3RydWN0IGNvdW50eVRvdGFscyBjb3VudHlGcmVxcyA9IGZyZXFPZklyaXNoQ291bnRpZXMoY291bnR5QXJyYXlMaXN0LDEyKTsKICAgIHByaW50ZigiQ29yayBDb3VudHk6ICVpXG4iLCBjb3VudHlGcmVxcy50b3RhbENvcmtDb2Rlcyk7CiAgICBwcmludGYoIkR1YmxpbiBDb3VudHk6ICVpXG4iLCBjb3VudHlGcmVxcy50b3RhbER1YmxpbkNvZGVzKTsKICAgIHByaW50ZigiR2Fsd2F5IENvdW50eTogJWlcbiIsIGNvdW50eUZyZXFzLnRvdGFsR2Fsd2F5Q29kZXMpOwogICAgcHJpbnRmKCJMaW1lcmljayBDb3VudHk6ICVpXG4iLCBjb3VudHlGcmVxcy50b3RhbExpbWVyaWNrQ29kZXMpOwogICAgcHJpbnRmKCJUaXBlcmFyeSBDb3VudHk6ICVpXG4iLCBjb3VudHlGcmVxcy50b3RhbFRpcGVyYXJ5Q29kZXMpOwogICAgcHJpbnRmKCJXYXRlcmZvcmQgQ291bnR5OiAlaVxuIiwgY291bnR5RnJlcXMudG90YWxXYXRlcmZvcmRDb2Rlcyk7CiAgICBwcmludGYoIkludmFsaWRDb3VudHlDb2RlczogJWlcbiIsIGNvdW50eUZyZXFzLnRvdGFsSW52YWxpZENvdW50eUNvZGVzKTsKCglyZXR1cm4gMDsKfQoKLy8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgovLyBGdW5jdGlvbjogZnJlcU9mSXJpc2hDb3VudGllcwovLyAKLy8gUHVycG9zZTogQ291bnQgdGhlIHRvdGFsIG51bWJlciBvZiBvY2N1cnJlbmNlcyBvZiBlYWNoIGNvdW50eSBjb2RlCi8vIAovLyBQYXJhbWV0ZXJzOgovLyAKLy8gICAgIGNvdW50eUFycmF5TGlzdCAtIGNoYXJhY3RlciBhcnJheSB0aGF0IGhvbGRzIHRoZSBsaXN0IG9mIGNvdW50eSBjb2RlcwovLyAgICAgc2l6ZSAtIHRoZSBudW1iZXIgb2YgZWxlbWVudHMgaW4gdGhlIGNudHlDb2RlcyBhcnJheQovLwovLyBSZXR1cm5zOiBhIHN0cnVjdHVyZSB0aGF0IGhvbGRzIHRoZSB0b3RhbCBudW1iZXIgb2Ygb2NjdXJyZW5jZXMgb2YgZWFjaCBjb3VudHkgY29kZQovLyAgCi8vKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKCgpzdHJ1Y3QgY291bnR5VG90YWxzIGZyZXFPZklyaXNoQ291bnRpZXMoY2hhciBjb3VudHlBcnJheUxpc3RbXSwgaW50IHNpemUpewoKICAgIHN0cnVjdCBjb3VudHlUb3RhbHMgbXlDb3VudHlUb3RhbHMgPSB7MCwwLDAsMCwwLDAsMH07ICAvLyBob2xkcyB0aGUgY291bnRyeSBjb3VudHMKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBhbmQgaW5pdGlhbGl6ZXMgdGhlbSB0byB6ZXJvCgogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBzaXplOyBpKyspIHsgCiAgICAgICAgc3dpdGNoIChjb3VudHlBcnJheUxpc3RbaV0pIHsgLypsb29waW5nIHRocm91Z2ggdGhlIGNvdW50eSBjb2RlcyBpbiB0aGUgbGlzdCBhbmQgdXNpbmcgdGhlIGNudHljb2RlIGFzIHRoZSBiYXNpcyBmb3IgdGhlIHN3aXRjaCBzdGF0ZW1lbnQgKi8KICAgICAgICBjYXNlICdDJzoKICAgICAgICBjYXNlICdjJzoKICAgICAgICAgICAgbXlDb3VudHlUb3RhbHMudG90YWxDb3JrQ29kZXMrKzsgLyogaWYgdGhlIGNudHkgY29kZSBpcyAnQycgb3IgJ2MnLCB0aGVuIGluY3JlbWVudGluZyB0aGUgY291bnQgYXNzb2NpYXRlZCB3aXRoIHRvdGFsIENvcmsgY291bnR5IGNvZGVzKi8KICAgICAgICAgICAgYnJlYWs7CgogICAgICAgIGNhc2UgJ0QnOgogICAgICAgIGNhc2UgJ2QnOgogICAgICAgICAgICBteUNvdW50eVRvdGFscy50b3RhbER1YmxpbkNvZGVzKz0xOyAvKnNhbWUgbG9naWMgYXMgbWVudGlvbmVkIGluIHRoZSBwcmV2aW91cyBjb21tZW50LCBidXQgZm9yIGEgZGlmZmVyZW50IGNvdW50eSwgd2l0aCBkaWZmZXJlbnQgYWJicmV2aWF0aW9ucyovCiAgICAgICAgICAgIGJyZWFrOwoKICAgICAgICBjYXNlICdHJzoKICAgICAgICBjYXNlICdnJzoKICAgICAgICAgICAgbXlDb3VudHlUb3RhbHMudG90YWxHYWx3YXlDb2Rlcys9MTsgCiAgICAgICAgICAgIGJyZWFrOwoKICAgICAgICBjYXNlICdMJzoKICAgICAgICBjYXNlICdsJzoKICAgICAgICAgICAgbXlDb3VudHlUb3RhbHMudG90YWxMaW1lcmlja0NvZGVzKz0xOwogICAgICAgICAgICBicmVhazsKICAgICAgICAKICAgICAgICBjYXNlICdUJzoKICAgICAgICBjYXNlICd0JzoKICAgICAgICAgICAgbXlDb3VudHlUb3RhbHMudG90YWxUaXBlcmFyeUNvZGVzKz0xOwogICAgICAgICAgICBicmVhazsKICAgICAgICAKICAgICAgICBjYXNlICdXJzoKICAgICAgICBjYXNlICd3JzoKICAgICAgICAgICAgbXlDb3VudHlUb3RhbHMudG90YWxXYXRlcmZvcmRDb2Rlcys9MTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgCiAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgbXlDb3VudHlUb3RhbHMudG90YWxJbnZhbGlkQ291bnR5Q29kZXMrPTE7IC8qaWYgbm9uZSBvZiB0aGUgb3RoZXIgY29uZGl0aW9ucyB3ZXJlIG1ldCwgdGhpcyBpcyBhbiBpbnZhbGlkIGNvdW50eSBjb2RlIGFuZCB0aGUgdmFyaWFibGUgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGhvbGRpbmcgdGhlIHRvdGFsIG9jY3VycmVuY2VzIG9mIGludmFsaWQgY291bnR5IGNvZGVzIHNob3VsZCBiZSBpbmNyZW1lbnRlZCBieSAxICovCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KCiAgICB9CiAgICAKICAgIHJldHVybiBteUNvdW50eVRvdGFsczsKCn0KCg==