#include #include #include #include #include #include #define TRUE 1 #define FALSE 0 #define PRECISION long double #define LNLN 100 int main (void) { char buffer[10] = "", dem_name[20] = "", rep_name[20] = "", district_name[20] = "", silly[20]; int i; long num_districts, rep_median_income, district_median_income; long district_votes, dem_votes, rep_votes; cin >> buffer; cin.getline(silly,LNLN); while (!cin.eof()) { if (strcmp(buffer, "START")) { cout << "First line in data set not START!\n"; cout << buffer << "\n"; exit(1); } // cout << "First line is " << buffer << "\n"; rep_votes = 0; dem_votes = 0; num_districts = 0; rep_median_income = 0; district_median_income = 0; district_votes = 0; dem_votes = 0; rep_votes = 0; cin.getline(dem_name,LNLN); cin.getline(rep_name,LNLN); cin >> num_districts; cin.getline(silly,LNLN); cin >> rep_median_income; cin.getline(silly,LNLN); // cout << "Dem: " << dem_name << "\n"; // cout << "Rep: " << rep_name << "\n"; // cout << "Districts: " << num_districts << "\n"; // cout << "Med. Income: " << rep_median_income << "\n"; for (i = 0; i < num_districts; i++) { cin.get(district_name,LNLN,','); cin.get(*silly); cin >> district_median_income; cin.get(*silly); cin >> district_votes; cin.get(*silly); // cout << "District name : " << district_name << "\n"; // cout << "Income : " << district_median_income << "\n"; if (district_median_income > rep_median_income) rep_votes += district_votes; else dem_votes += district_votes; } cin >> buffer; cin.getline(silly, LNLN); if (strcmp(buffer,"END")) { cout << "Last line in data set not END!"; exit(1); } // cout << "Done -- Dem: " << dem_name << "\n"; // cout << "Rep: " << rep_name << "\n"; // cout << "Districts: " << num_districts << "\n"; // cout << "Med. Income: " << rep_median_income << "\n"; /* Print the result */ if (dem_votes > rep_votes) cout << dem_name << "," << dem_votes << "\n"; else cout << rep_name << "," << rep_votes << "\n"; /* Try to start reading in next data set */ cin >> buffer; cin.getline(silly,LNLN); } return (0); }