#if 0
By Cool_Breeze
Dev-C++ 5.11
x.c
#endif
#include <stdio.h>
#include <string.h>
void sawp(float* p1, float* p2,short len);
int main(void)
{
static float Achievement[300][5];
//0学号,1语文,2数学,3英语,4三科总和;
short n=0;
scanf("%d",&n);
getchar();
register short i=0;
for (i=0;i<n;i++)
{
Achievement[i][0]=i+1;
scanf("%f %f %f",&Achievement[i][1],&Achievement[i][2],&Achievement[i][3]);
getchar();
Achievement[i][4]=Achievement[i][1]+Achievement[i][2]+Achievement[i][3];
}
//sort
register short j=0;
for (i=0;i<n-1;i++)
for (j=i+1;j<n;j++)
{
if (Achievement[j][4] > Achievement[i][4])
{
sawp(&Achievement[i][0],&Achievement[j][0],5);
continue;
}
else if (Achievement[j][4] == Achievement[i][4])//总成绩相等
{
if (Achievement[j][1] == Achievement[i][1])//语文相等
{
if (Achievement[j][0] > Achievement[i][0])// 比较学号
sawp(&Achievement[i][0],&Achievement[j][0],5);
continue;
}
else if (Achievement[j][1] > Achievement[i][1])
{
sawp(&Achievement[i][0],&Achievement[j][0],5);
continue;
}
}
}
for (i=0;i<5;i++)//前5名
printf("%f %f\n",Achievement[i][0],Achievement[i][4]);
return 0;
}
void sawp(float* p1, float* p2,short len)
{
register float t=0;
for (;len>0;p1++,p2++,len--)
t=*p1,*p1=*p2,*p2=t;
}
6
90 67 80
87 66 91
78 89 91
88 99 77
67 89 64
78 89 98
6.000000 265.000000
4.000000 264.000000
3.000000 258.000000
2.000000 244.000000
1.000000 237.000000
--------------------------------
Process exited after 11.32 seconds with return value 0
请按任意键继续. . .
|