『求助』C语言设置投票问题,如何能以淘汰形式继续投票
代码就不全贴出来了,我想问的是如何在不大量改变代码的情况下能以淘汰形式继续投票,直到选出优胜者,现在正在为投票不能继续下去而苦恼,总感觉好像再加上一个指令就能解决问题的感觉,麻烦高手们给我指出来,最好列出修改后版本,多谢#include <stdio.h>
#include <conio.h>
main()
{
char a[3];
int n,i,na=0,nb=0,nc=0,nd=0,ne=0,nf=0,ng=0;
printf("Please enter the number of votes\n");
scanf("%d",&n);
fflush(stdin);
for(i=1; i<=n;i++)
{
printf("Please %d voting:\n",i);
gets(a);
if(a[0]==a[1]||a[0]==a[2]||a[1]==a[2])
{
printf("Invalid vote\n");
}
else
{
if(a[0]=='a')na+=1;
if(a[0]=='b')nb+=1;
if(a[0]=='c')nc+=1;
if(a[0]=='d')nd+=1;
if(a[0]=='e')ne+=1;
if(a[0]=='f')nf+=1;
if(a[0]=='g')ng+=1;
if(a[1]=='a')na+=1;
if(a[1]=='b')nb+=1;
if(a[1]=='c')nc+=1;
if(a[1]=='d')nd+=1;
if(a[1]=='e')ne+=1;
if(a[1]=='f')nf+=1;
if(a[1]=='g')ng+=1;
if(a[2]=='a')na+=1;
if(a[2]=='b')nc+=1;
if(a[2]=='c')nd+=1;
if(a[2]=='d')ne+=1;
if(a[2]=='e')nf+=1;
if(a[2]=='f')ng+=1;
if(a[2]=='g')ng+=1;
}
}
if(na>nb&&na>nc&&na>nd&&na>ne&&na>nf&&na>ng)
printf("Congratulations [Michael D. Higgins] to win\n");
else if(nb>na&&nb>nc&&nb>nd&&nb>ne&&nb>nf&&nb>ng)
printf("Congratulations [Sean Gallagher] to win\n");
else if(nc>na&&nc>nb&&nc>nd&&nc>ne&&nc>nf&&nc>ng)
printf("Congratulations [Martin McGuinness] to win\n");
else if(nd>na&&nb>nb&&nb>nc&&nb>ne&&nb>nf&&nb>ng)
printf("Congratulations [Gay Mitchell] to win\n");
else if(ne>na&&ne>nb&&ne>nc&&ne>nd&&ne>nf&&ne>ng)
printf("Congratulations [David Norris] to win\n");
else if(nf>na&&nf>nb&&nf>nc&&nf>nd&&nf>ne&&nf>ng)
printf("Congratulations [Dana Rosemary] to win\n");
else if(ng>na&&ng>nb&&ng>nc&&ng>nd&&ng>ne&&ng>nf)
printf("Congratulations [Mary Davis] to win\n");
else
printf("Continue vote\n");
printf("Score: Michael D. Higgins:%d Sean Gallagher:%d\n Martin McGuinness:%d Gay Mitchell:%d\n David Norris:%d Dana Rosemary:%d\n Mary Davis:%d\n",na,nb,nc,nd,ne,nf,ng);
getch();
}