凑合着用吧,有些地方不完善,没时间做.你参考吧.
在VC++里编译成功
#include "iostream.h"
#include "string.h"
#include "time.h"
#include "stdlib.h"
#include "stdio.h"
#include "windows.h"
#define Number 40 //委员人数
void main ()
{int Selection[4][Number]={0};
int All1[Number+1]={0};//投票规则1,把每个委员按号码拼音排好,如敖小明:1,白小红:2。这一步请你自己做。
int All2[Number+1]={0};//2投票规则:每个委员轮流投票,电脑提示请输入你的投票,你只需输入所选同学的学号,如果弃权请按0。
int Candidate[Number+1][2];
int i,j,k,flag;
for(i=1;i<=Number;i++)
{Candidate[i][0]=i;
srand((unsigned)time(NULL));
Candidate[i][1]=rand()%2;
Sleep(200);
}
for(i=1;i<=Number;i++)
cout<
//本表用于女生部长选举,实践表情况应根据你班的实际男女生分布进行输入。
for(i=1;i<=Number;i++)
{cout<<"Your student number is"<<' '<j=getchar();
getchar();
while((j<=-1)&&(j>=Number+1))
{cout<<"Error! Please input again!"<j=getchar();
getchar();
}
All1[j]+=1;
}//此时主席的投票情况已经存在于表All1中。
for(j=1;j<=Number;j++)
All2[j]=All1[j];//把All1复制到All2中用于查找最多票数的下标。
for(i=1;i<=Number-1;i++)
for(j=i+1;j<=Number;j++)
if(All1[i]{k=All1[j];
All1[i]=All1[j];
All1[j]=k;
}//对选票进行排序,最多的票数存All1[1]中。
flag=All1[1];
j=0;
for(i=1;i<=Number;i++)
if(All2[i]==flag)
{Selection[0][j]=i;
j++;
}
cout<<"Student number of the person who gets most votes of chairman is:"<for(i=0;i<=Number-1;i++)
{if (Selection[0][i]!=0)
cout<else
break;
}//有可能出现同票的现象,极端情况下全班同学每人都有一票.本程序已考虑了该问题.可以输出多个同票的学号.
for(j=1;j<=Number;j++)
All1[j]=0;
cout<<"*******************************************************************"<for(i=1;i<=Number;i++)
{cout<<"Your student number is"<<' '<j=getchar();
getchar();
while((j<=-1)&&(j>=Number+1))
{cout<<"Error! Please input again!"<j=getchar();
getchar();
}
All1[j]+=1;
}
for(j=1;j<=Number;j++)
All2[j]=All1[j];
for(i=1;i<=Number-1;i++)
for(j=i+1;j<=Number;j++)
if(All1[i]{k=All1[j];
All1[i]=All1[j];
All1[j]=k;
}
flag=All1[1];
j=0;
for(i=1;i<=Number;i++)
if(All2[i]==flag)
{Selection[1][j]=i;
j++;
}
cout<<"Student number of the person who gets most votes of vice chairman is:"<for(i=0;i<=Number-1;i++)
{if (Selection[1][i]!=0)
cout<else
break;
}
for(j=1;j<=Number;j++)
All1[j]=0;
cout<<"*******************************************************************"<for(i=1;i<=Number;i++)
{cout<<"Your student number is"<<' '<j=getchar();
getchar();
while((j<=-1)&&(j>=Number+1))
{cout<<"Error! Please input again!"<j=getchar();
getchar();
}
All1[j]+=1;
}
for(j=1;j<=Number;j++)
All2[j]=All1[j];
for(i=1;i<=Number-1;i++)
for(j=i+1;j<=Number;j++)
if(All1[i]{k=All1[j];
All1[i]=All1[j];
All1[j]=k;
}
flag=All1[1];
j=0;
for(i=1;i<=Number;i++)
if(All2[i]==flag)
{Selection[2][j]=i;
j++;
}
cout<<"Student number of the person who gets most votes of Learning Minister is:"<for(i=0;i<=Number-1;i++)
{if (Selection[2][i]!=0)
cout<else
break;
}
for(j=1;j<=Number;j++)
All1[j]=0;
cout<<"*******************************************************************"<i=1;
while(i<=Number)
{cout<<"Your student number is"<<' '<j=getchar();
getchar();
while((j<=-1)&&(j>=Number+1))
{cout<<"Error! Please input again!"<j=getchar();
getchar();
}
while(Candidate[j][1]==1)
{cout<<"Error! Your selection must be a girl. Please
--------------------next---------------------
阅读(1087) | 评论(0) | 转发(0) |