return 0; }
if (winner != NULL) { printf("\nThe winner is: %s\n", winner); } else { printf("\nNo winner.\n"); }
// Structure to represent a voter typedef struct { char preferences[MAX_CANDIDATES][MAX_NAME_LENGTH]; } Voter;
// Update preferences for (int i = 0; i < num_voters; i++) { for (int j = 0; j < num_candidates; j++) { if (strcmp(voters[i].preferences[j], candidates[min_vote_index].name) == 0) { for (int k = j; k < num_candidates - 1; k++) { strcpy(voters[i].preferences[k], voters[i].preferences[k+1]); } strcpy(voters[i].preferences[num_candidates-1], ""); j--; } } }
return 0; }
if (winner != NULL) { printf("\nThe winner is: %s\n", winner); } else { printf("\nNo winner.\n"); } Cs50 Tideman Solution
// Structure to represent a voter typedef struct { char preferences[MAX_CANDIDATES][MAX_NAME_LENGTH]; } Voter; return 0; } if (winner
// Update preferences for (int i = 0; i < num_voters; i++) { for (int j = 0; j < num_candidates; j++) { if (strcmp(voters[i].preferences[j], candidates[min_vote_index].name) == 0) { for (int k = j; k < num_candidates - 1; k++) { strcpy(voters[i].preferences[k], voters[i].preferences[k+1]); } strcpy(voters[i].preferences[num_candidates-1], ""); j--; } } } } else { printf("\nNo winner.\n")