#include <stdio.h>
int 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' } ;
countCntyOccur( cntyCodes, 14 ) ;
return 0 ;
}
int countCntyOccur ( char cntyCodes[ ] , int size) {
int totalCorkCodes= 0 ;
int totalDublinCodes= 0 ;
int totalGalwayCodes= 0 ;
int totalLimerickCodes= 0 ;
int totalTiperaryCodes= 0 ;
int totalWaterfordCodes= 0 ;
int totalInvalidCountryCodes= 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 :
totalInvalidCountryCodes+= 1 ;
}
}
printf ( "The number of Cork codes is: %i\n " , totalCorkCodes
) ; printf ( "The number of Dublin codes is: %i\n " , totalDublinCodes
) ; printf ( "The number of Galway codes is: %i\n " , totalGalwayCodes
) ; printf ( "The number of Limerick codes is: %i\n " , totalLimerickCodes
) ; printf ( "The number of Waterford codes is: %i\n " , totalWaterfordCodes
) ; // struct countryTotals{
// int totalCorkCodes;
// int totalDublinCodes;
// int totalGalwayCodes;
// int totalLimerickCodes;
// int totalTiperaryCodes;
// int totalWaterfordCodes;
// int totalInvalidCountryCodes;
// }
// return countryTotals;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgY291bnRDbnR5T2NjdXIgKGNoYXIgY250eUNvZGVzW10saW50IHNpemUpOwoKaW50IG1haW4odm9pZCkgewoJY2hhciBjbnR5Q29kZXNbXT0geydDJywnYycsJ2MnLCdEJywnZCcsJ0cnLCdMJywnbCcsJ2wnLCdMJywnVCcsJ3QnLCd0JywnVycsJ3cnLCdYJ307CiAgICBjb3VudENudHlPY2N1cihjbnR5Q29kZXMsMTQpOwoJcmV0dXJuIDA7Cn0KCgppbnQgY291bnRDbnR5T2NjdXIgKGNoYXIgY250eUNvZGVzW10saW50IHNpemUpewoKICAgIGludCB0b3RhbENvcmtDb2Rlcz0wOwogICAgaW50IHRvdGFsRHVibGluQ29kZXM9MDsKICAgIGludCB0b3RhbEdhbHdheUNvZGVzPTA7CiAgICBpbnQgdG90YWxMaW1lcmlja0NvZGVzPTA7CiAgICBpbnQgdG90YWxUaXBlcmFyeUNvZGVzPTA7CiAgICBpbnQgdG90YWxXYXRlcmZvcmRDb2Rlcz0wOwogICAgaW50IHRvdGFsSW52YWxpZENvdW50cnlDb2Rlcz0wOwoKCiAgICBmb3IgKGludCBpID0gMDsgaSA8IHNpemU7IGkrKykgewogICAgICAgIC8vIFN3aXRjaCBzdGF0ZW1lbnQKICAgICAgICBzd2l0Y2ggKGNudHlDb2Rlc1tpXSkgewogICAgICAgIGNhc2UgJ0MnOgogICAgICAgIGNhc2UgJ2MnOgogICAgICAgICAgICB0b3RhbENvcmtDb2Rlcys9MTsKICAgICAgICAgICAgYnJlYWs7CgogICAgICAgIGNhc2UgJ0QnOgogICAgICAgIGNhc2UgJ2QnOgogICAgICAgICAgICB0b3RhbER1YmxpbkNvZGVzKz0xOwogICAgICAgICAgICBicmVhazsKCiAgICAgICAgY2FzZSAnRyc6CiAgICAgICAgY2FzZSAnZyc6CiAgICAgICAgICAgIHRvdGFsR2Fsd2F5Q29kZXMrPTE7CiAgICAgICAgICAgIGJyZWFrOwoKICAgICAgICBjYXNlICdMJzoKICAgICAgICBjYXNlICdsJzoKICAgICAgICAgICAgdG90YWxMaW1lcmlja0NvZGVzKz0xOwogICAgICAgICAgICBicmVhazsKICAgICAgICAKICAgICAgICBjYXNlICdUJzoKICAgICAgICBjYXNlICd0JzoKICAgICAgICAgICAgdG90YWxUaXBlcmFyeUNvZGVzKz0xOwogICAgICAgICAgICBicmVhazsKICAgICAgICAKICAgICAgICBjYXNlICdXJzoKICAgICAgICBjYXNlICd3JzoKICAgICAgICAgICAgdG90YWxXYXRlcmZvcmRDb2Rlcys9MTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgCiAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgdG90YWxJbnZhbGlkQ291bnRyeUNvZGVzKz0xOwogICAgICAgIH0KCiAgICB9CiAgICBwcmludGYoIlRoZSBudW1iZXIgb2YgQ29yayBjb2RlcyBpczogJWlcbiIsIHRvdGFsQ29ya0NvZGVzKTsKICAgIHByaW50ZigiVGhlIG51bWJlciBvZiBEdWJsaW4gY29kZXMgaXM6ICVpXG4iLCB0b3RhbER1YmxpbkNvZGVzKTsKICAgIHByaW50ZigiVGhlIG51bWJlciBvZiBHYWx3YXkgY29kZXMgaXM6ICVpXG4iLCB0b3RhbEdhbHdheUNvZGVzKTsKICAgIHByaW50ZigiVGhlIG51bWJlciBvZiBMaW1lcmljayBjb2RlcyBpczogJWlcbiIsIHRvdGFsTGltZXJpY2tDb2Rlcyk7CiAgICBwcmludGYoIlRoZSBudW1iZXIgb2YgV2F0ZXJmb3JkIGNvZGVzIGlzOiAlaVxuIiwgdG90YWxXYXRlcmZvcmRDb2Rlcyk7CiAgICAvLyBzdHJ1Y3QgY291bnRyeVRvdGFsc3sKICAgIC8vICAgICBpbnQgdG90YWxDb3JrQ29kZXM7CiAgICAvLyAgICAgaW50IHRvdGFsRHVibGluQ29kZXM7CiAgICAvLyAgICAgaW50IHRvdGFsR2Fsd2F5Q29kZXM7CiAgICAvLyAgICAgaW50IHRvdGFsTGltZXJpY2tDb2RlczsKICAgIC8vICAgICBpbnQgdG90YWxUaXBlcmFyeUNvZGVzOwogICAgLy8gICAgIGludCB0b3RhbFdhdGVyZm9yZENvZGVzOwogICAgLy8gICAgIGludCB0b3RhbEludmFsaWRDb3VudHJ5Q29kZXM7ICAgCiAgICAvLyB9CiAgICAvLyByZXR1cm4gY291bnRyeVRvdGFsczsKCn0=