该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include#include
#include
#define N 40 /*班级人数*/
#define M 6 /*每人的投票数*/
struct std
{
int num, num_vote, tou[M]; /*自己的学号,获得的投票数,投的谁的票 */
char name[20];
}std[N], temp;
/*班级信息输入*/
void input_all_std (){
int i;
printf ("输入全班信息\n\n");
for (i = 0; i
{printf ("学生%d的姓名和学号:", i + 1);
scanf ("%s %d", std[i].name,&std[i].num);
std[i].num_vote = 0;
}
system ("cls");
printf ("姓名: 学号:\n");
for (i = 0; i
printf ("%-20s%d\n",std[i].name, std[i].num);
}/*根据学生的学号查找到结构体编号*/
int find_std (int num){int n;
for (n = 0; n
{if (std[n].num == num)
{return n;};}return -1;}void vote ()
{int i = N, j, t, temp;
system ("cls");
loop:while (i)
{printf ("输入你的学号:");
scanf ("%d",&temp);
t = find_std (temp);
if (t == -1){printf ("学号错误!");
goto loop;
}
for (j = 0; j
{printf ("第%d票投给:", j + 1);
scanf ("%d",&std[t].tou[j]);
temp = find_std (std[t].tou[j]);
if (temp == -1)
{printf ("\n投票无效!\n");
j--;
continue;
}
std[temp].num_vote++;
}
system ("cls");
i = i - 1;}}
void sort ()
{int i, j, k, n, t;
for (i = 0; i
{k = i;
for (j = i + 1; j
if (std[j].num_vote>std[k].num_vote)
k = j;
if (k != i)
{temp = std[i];
std[i] = std[j];
std[j] = temp;}}
for (i = 0; i
{for (j = 0; j
{k = j;for (n = j + 1; n
if (std[i].tou[j]>std[i].tou[k])
k = j;
if (k != j)
{t = std[i].tou[j];
std[i].tou[j] = std[i].tou[k];
std[i].tou[k] = t;}}}}
/*输出选举结果*/
void output_list ()
{int i;system ("cls");
printf ("最终的选举结果为:\n姓名: 得票数:\n");
for (i = 0; i
printf ("%-20s%d\n", std[i].name, std[i].num_vote);}
/*与结果完全相符的投票人姓名*/void all_right (){int i,j,flag=0;
system ("cls");
printf ("与结果完全相符的投票人姓名:\n");
for (i = 0; i
{for(j = 0; j
{if (std[i].tou[j] == std[j].num)
{flag=1; continue;}
else {flag=0;break;}}
if(flag==1)printf ("%-s\n", std[i].name);}}/*输出班委名单*/void out_lead_list (){int i;float temp;system ("cls");printf ("班委名单: 得票率:\n");for (i = 0; i<6; i++){temp = (float) std[i].num_vote;printf ("%-10s%2.4f\n", std[i].name, temp / N * 1.0);}}
/*查找特定人员投票信息*/void find_info (){int a;system ("cls");loop:printf ("输入所要查找的学号:");scanf ("%d",&a);a = find_std (a);if (a == -1){printf ("此学号不存在!");system ("cls");goto loop;}system ("cls");printf ("姓名:%s\n得票数:%d\n投票情况:\n%d\n%d\n%d\n%d\n%d\n%d\n\n",std[a].name, std[a].num_vote, std[a].tou[0], std[a].tou[1],std[a].tou[2], std[a].tou[3], std[a].tou[04], std[a].tou[5]);}void main (){int flag=-1;
input_all_std ();loop:while(flag){printf ("--------------------------------\n");printf ("1.开始投票\n");printf ("2.当选班委的名单\n");printf ("3.查看投票信息\n");printf ("4.与投票结果完全相符的投票人\n");printf ("0.退出\n");printf ("--------------------------------\n");printf ("选择:");scanf ("%d",&flag);system ("cls");switch (flag){case 1:{vote ();sort ();break;}case 2:{out_lead_list ();break;}case 3:{find_info ();break;}case 4:{all_right ();break;}case 0:{printf ("Byebye! ^_^");getch ();exit (0);}default:{printf ("输入错误!请重新输入。\n");}goto loop;}}}
还有哪些要改的 ????