|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
[ 本帖最后由 veer786 于 2013-10-20 17:50 编辑 ]
#include<stdio.h>
int compare(char source[],char destination[]);
struct Person* max_person(struct Person *a,struct Person *b, struct Person *c);
struct Person
{
char name[20];
int vote;
};
int main()
{
struct Person person[3] = {{"张三",0},{"李四",0},{"王五",0}};
struct Person temp;
struct Person *p;
int j = 1;
int i;
printf("候选人:\n张三\t李四\t王五\n");
while(j <=10)
{
printf("请输入第%d位候选人姓名:\n",j);
if(compare(gets(temp.name),"张三"))
{
person[0].vote++;
}
else if(compare(gets(temp.name),"李四"))
{
person[1].vote++;
}
else if(compare(gets(temp.name),"王五"))
{
person[2].vote++;
}
else
{
;
}
j++;
}
p = max_person(&person[0],&person[1],&person[2]);
for(i = 0;i<3;i++)
{
printf("%s得票%d\n",person[i].name,person[i].vote);
}
printf("得票最高的是:%s\n",p->name);
return 0;
}
int compare(char source[],char destination[])
{
int i = 0;
while(source[i] != '\0')
{
if(source[i] == destination[i])
{
;
}
else
{
return 0;
}
i++;
}
return 1;
}
struct Person* max_person(struct Person *a,struct Person *b, struct Person *c)
{
if(a->vote<b->vote)
{
a = b;
}
if(a->vote<c->vote)
{
a = c;
}
return a;
}
为什么输入候选人不是一次只输入一个人? |
-
|