2017.2.20
When I looked at C++ in the past, I found that I was confused and couldn't understand anything. Now I look back and find that it is still very simple, mainly because I didn't study hard before.
//There are 10 people voting today, enter the names of these 10 people from the keyboard, and request the final output of the votes of each candidate #include<iostream> using namespace std; struct Person{ char name[20]; int count; }; int main(){ Person leader[3]={"Li",0,"Zhang",0,"Sun",0}; //Define an array of person type, containing the names of 3 candidates and the current number of votes int i,j; char leader_name[20]; //leader_name is the name selected by the voter for(i=0;i<10;i++) { cin>>leader_name; //Enter the names on the 10 tickets successively for(j=0;j<3;j++) //Compare the name on the ticket with the names of the 3 candidates if(strcmp(leader_name,leader[j].name)==0)leader[j].count++; } //If it is the same as a candidate, add one vote to him cout<<endl; for(i=0;i<3;i++){ //Output the names of 3 candidates and the final number of votes cout<<leader[i].name<<":"<<leader[i].count<<endl;} return 0; }