标签:2024.12,name,tmpname,int,xm,29,选票,piao,printf From: https://blog.csdn.net/2302_79237935/article/details/144811441#include <stdio.h>
#include <string.h>struct Xuanmin{
char name[32];
int piao;
};int main()
{
struct Xuanmin xm[3];
int i;
int j;
int len;
int total;
char tmpname[32];
len=sizeof(xm)/sizeof(xm[0]);
for(i=0;i<len;i++){
xm[i].piao=0;
printf("请输入第%d个候选人的名字:\n");
scanf("%s",xm[i].name);
}
for(i=0;i<5;i++){
printf("请输入你要投给谁:\n");
memset(tmpname,'\0',sizeof(tmpname));
scanf("%s",tmpname);
for(j=0;j<len;j++){
if(strcmp(tmpname,xm[j].name)==0){
xm[j].piao++;
}
}
}
for(i=0;i<len;i++){
printf("名字:%s,票数;%d\n",xm[i].name,xm[i].piao);
}
return 0;
}