编辑代码

#include <iostream>

using namespace std;

const int MAX_CANDIDATES = 1000; // Adjust the maximum number of candidates as needed

void avoidDuplicateVotes(const int votes[], int size) {
    bool votedCandidates[MAX_CANDIDATES] = {false};

    for (int i = 0; i < size; ++i) {
        int candidate = votes[i];
        if (!votedCandidates[candidate]) {
            // This candidate has not been voted yet
            cout << "Vote for Candidate " << candidate << "\n";
            votedCandidates[candidate] = true;
        } else {
            // This candidate has already been voted, avoiding duplicate vote
            cout << "Duplicate vote for Candidate " << candidate << ", vote ignored\n";
        }
    }
}

int main() {
    int votes[] = {1, 2, 3, 4, 1, 2, 5, 3, 6, 4};
    int size = sizeof(votes) / sizeof(votes[0]);

    cout << "Voting results:\n";
    for (int i = 0; i < size; ++i)
        cout << votes[i] << " ";
    cout << "\n";

    cout << "Avoiding duplicate votes:\n";
    avoidDuplicateVotes(votes, size);

    return 0;
}