结构体 选举
有没有老哥帮忙解释一下这段代码,新手看不太懂#include<stdio.h>
#include<math.h>
#include<string>
#define n 10
struct person
{ char name[20];
int count;
};
void main()
{ struct person leader[4]={{"wang",0},{"zhang",0},{"zhou",0},{"gao",0}};
char name[20];
int i,j;
for(i=0;i<n;i++)
{ gets(name);
for(j=0;j<4;j++)
if (strcmp(name,leader[j].name)==0)
{leader[j].count++;
break;}
}
printf("\n");
for(j=0;j<4;j++)
printf("%s:%d\n",leader[j].name,leader[j].count);
}