对候选人得票的统计程序

 1 #include <iostream>
 2 #include <string.h>
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 using namespace std;
 5 struct Person
 6 {
 7     char name[20];
 8     int count;
 9 };
10 
11 int main(int argc, char** argv) {
12     Person leader[3]={"Li",0,"Zhang",0,"Fun",0};
13     int i,j;
14     char leader_name[20];
15     for(i=0;i<10;i++)
16     {
17         cin >>leader_name;
18         for(j=0;j<3;j++)
19         if(strcmp(leader_name,leader[j].name)==0)leader[j].count++;
20     }
21     cout<<endl;
22     for(i=0;i<3;i++)
23     {
24         cout<<leader[i].name<<":"<<leader[i].count<<endl;
25     }
26     return 0;
27 }

 

posted @ 2018-08-01 15:59  borter  阅读(946)  评论(0编辑  收藏  举报