flag34 志愿投档系统

# include
# include
typedef struct stuent
{
int id;
int a[2];
int b[3];
int sum;
int rank;
}Stu,*Pstu;
typedef struct school
{
int schoolid;
int max;
int cnt;
int studentid[10];
int prestudentid;
}Sch,*Psch;
void sort (Pstu student,int T);
void xianshi (Pstu student);
void toudang(Pstu student,Psch school,int T1,int T2);
void toudangxianshi (Psch school);
void sortid (Pstu student,int T);
int main()
{
int T1=11,T2=6,T3=3;
Pstu student =(Pstu)malloc(sizeof(Stu)*T1);
Psch school =(Psch)malloc(sizeof(Sch)*T2);
student[0].id=0;
student[0].a[0]=100;
student[0].a[1]=100;
student[0].b[0]=0;
student[0].b[1]=1;
student[0].b[2]=2;
student[1].id=1;
student[1].a[0]=60;
student[1].a[1]=60;
student[1].b[0]=2;
student[1].b[1]=3;
student[1].b[2]=5;//为了方便调试 直接给出了输入 
student[2].id=2;
student[2].a[0]=100;
student[2].a[1]=90;
student[2].b[0]=0;
student[2].b[1]=3;
student[2].b[2]=4;
student[3].id=3;
student[3].a[0]=90;
student[3].a[1]=100;
student[3].b[0]=1;
student[3].b[1]=2;
student[3].b[2]=0;
student[4].id=4;
student[4].a[0]=90;
student[4].a[1]=90;
student[4].b[0]=5;
student[4].b[1]=1;
student[4].b[2]=3;
student[5].id=5;
student[5].a[0]=80;
student[5].a[1]=90;
student[5].b[0]=1;
student[5].b[1]=0;
student[5].b[2]=2;
student[6].id=6;
student[6].a[0]=80;
student[6].a[1]=80;
student[6].b[0]=0;
student[6].b[1]=1;
student[6].b[2]=2;
student[7].id=7;
student[7].a[0]=80;
student[7].a[1]=80;
student[7].b[0]=0;
student[7].b[1]=1;
student[7].b[2]=2;
student[8].id=8;
student[8].a[0]=80;
student[8].a[1]=70;
student[8].b[0]=1;
student[8].b[1]=3;
student[8].b[2]=2;
student[9].id=9;
student[9].a[0]=70;
student[9].a[1]=80;
student[9].b[0]=1;
student[9].b[1]=2;
student[9].b[2]=3;
student[10].id=10;
student[10].a[0]=100;
student[10].a[1]=100;
student[10].b[0]=0;
student[10].b[1]=2;
student[10].b[2]=4;

for (int i=0;i {
school[i].schoolid=i;
school[i].cnt=0;
}
school[0].max=2;
school[1].max=1;
school[2].max=2;
school[3].max=2;
school[4].max=2;
school[5].max=3;
for(int i=0;i {
student[i].sum=student[i].a[0]+student[i].a[1];
}
sort(student,T1);
//xianshi(student);
//sortid(student,T1);
toudang(student,school,T1,T2);
toudangxianshi(school);

return 0;
}
void sortid (Pstu student,int T)
{
Stu tmp;
bool change=true;
for(int i=0;i {
change =false;
for(int j=T-1;j>i;j--)
{
if(student[j].id {
tmp=student[j];
student[j]=student[j-1];
student[j-1]=tmp;
change=true;
}
}
}
}
void sort (Pstu student,int T)
{
Stu tmp;
bool change=true;
for(int i=0;i {
change =false;
for(int j=T-1;j>i;j--)
{
if(student[j].sum>student[j-1].sum)
{
tmp=student[j];
student[j]=student[j-1];
student[j-1]=tmp;
change=true;
}
if(student[j].sum==student[j-1].sum)
{
if(student[j].a[0]>student[j-1].a[0])
{
tmp=student[j];
student[j]=student[j-1];
student[j-1]=tmp;
change=true;
}
}
}
}
student[0].rank=0;
for(int i=1;i {
if(student[i].sum==student[i-1].sum)
{
if(student[i].a[0] student[i].rank=student[i-1].rank+1;
else
student[i].rank=student[i-1].rank;
}
else
student[i].rank=i;
}
}
void xianshi (Pstu student)
{
for(int i=0;i<11;i++)
{
printf("%d  %d    \n",student[i].id,student[i].rank);
}
}
void toudangxianshi (Psch school)
{
int tmp;
for(int i=0;i<6;i++)
{
if(school[i].cnt>=2)
{
for(int k=0;k for(int j=school[i].cnt-1;j>k;j--)
{
if(school[i].studentid[j] {
tmp=school[i].studentid[j];
school[i].studentid[j]=school[i].studentid[j-1];
school[i].studentid[j-1]=tmp;
}
}

}
}
for(int i=0;i<6;i++)
{
for(int j=0;j {
printf("%d ",school[i].studentid[j]);
}
printf("\n");
}
}
void toudang(Pstu student,Psch school,int T1,int T2)
{
for(int i=0;i {

for(int j=0;j<3;j++)
{
if(school[student[i].b[j]].cnt {
school[student[i].b[j]].studentid[school[student[i].b[j]].cnt]=student[i].id;
school[student[i].b[j]].cnt++;
school[student[i].b[j]].prestudentid=student[i].id;
break;
}
else if (school[student[i].b[j]].cnt>=school[student[i].b[j]].max && student[i].rank==student[school[student[i].b[j]].prestudentid].rank)
{
school[student[i].b[j]].studentid[school[student[i].b[j]].cnt]=student[i].id;
school[student[i].b[j]].cnt++;
break;
}
}
}
}

你可能感兴趣的:(flag34 志愿投档系统)