#include <iostream>
#include <tr1/unordered_map>
#include <string>
void vote(std::tr1::unordered_map<std::string, int>& candidateVotes, const std::string& votedCandidate) {
std::tr1::unordered_map<std::string, int>::iterator it = candidateVotes.find(votedCandidate);
if (it == candidateVotes.end()) {
candidateVotes[votedCandidate] = 1;
std::cout << "投票成功!" << std::endl;
} else {
std::cout << "您已经投过票了,不能重复投票。" << std::endl;
}
}
int main() {
std::tr1::unordered_map<std::string, int> candidateVotes;
std::string candidateNames[] = {"Candidate1", "Candidate2", "Candidate3", "Candidate4"};
std::string votedCandidate1 = "Candidate2";
vote(candidateVotes, votedCandidate1);
std::string votedCandidate2 = "Candidate2";
vote(candidateVotes, votedCandidate2);
return 0;
}