杭电 ACM 1084
http://acm.hdu.edu.cn/showproblem.php?pid=1084
下面是我的代码 不知WA的 原因
#include <iostream>
#include <string.h>
using namespace std;
struct stu
{
int p ;
char time[20];
int grade;
int rank;
};
char min4[20],min3[20],min2[20],min1[20];//用来记录最短时间
void GetMin(stu* student);
int main()
{
struct stu TheStu[100];
int StuNumber;
int i ,j,k,m,n;
while( cin>>StuNumber ,StuNumber > 0 )
{
for ( i = 0 ; i< StuNumber ; i++)
{
j=0 , k=0, m =0, n = 0;
cin>>TheStu[i].p>>TheStu[i].time;//input
strcpy(min4,"AAAAAAAAAAAA");
strcpy(min3,"AAAAAAAAAAAA");
strcpy(min2,"AAAAAAAAAAAA");
strcpy(min1,"AAAAAAAAAAAA");
//set grage if p = 0 or p = 5
if ( TheStu[i].p == 5)
{
TheStu[i].grade = 100;
}
if ( TheStu[i].p == 0 )
{
TheStu[i].grade = 50;
}
if ( TheStu[i].p == 4 )
{
TheStu[i].rank = n ++;
GetMin(&TheStu[i]);
}
if ( TheStu[i].p == 3 )
{
TheStu[i].rank = m ++;
GetMin(&TheStu[i]);
}
if ( TheStu[i].p == 2)
{
TheStu[i].rank = k ++;
GetMin(&TheStu[i]);
}
if ( TheStu[i].p == 1 )
{
TheStu[i].rank = j ++;
GetMin(&TheStu[i]);
}
}
for ( i = 0 ; i< StuNumber ; i++)
{
if ( TheStu[i].p == 5 || TheStu[i].p == 0 )
{
cout<<TheStu[i].grade<<endl;
}
if ( TheStu[i].p == 4 )
{
if ( TheStu[i].rank <= n/2 && strcmp(TheStu[i].time , min4) <= 0 )
{
TheStu[i].grade = 95 ;
}
else
{
TheStu[i].grade = 90 ;
}
cout<<TheStu[i].grade<<endl;
}
if ( TheStu[i].p == 3 )
{
if ( TheStu[i].rank <= n/2 && strcmp(TheStu[i].time , min3) <= 0 )
{
TheStu[i].grade = 85 ;
}
else
{
TheStu[i].grade = 80 ;
}
cout<<TheStu[i].grade<<endl;
}
if ( TheStu[i].p == 2)
{
if ( TheStu[i].rank <= n/2 && strcmp(TheStu[i].time , min2) <= 0 )
{
TheStu[i].grade = 75 ;
}
else
{
TheStu[i].grade = 70 ;
}
cout<<TheStu[i].grade<<endl;
}
if ( TheStu[i].p == 1 )
{
if ( TheStu[i].rank <= n/2 && strcmp(TheStu[i].time , min1) <= 0 )
{
TheStu[i].grade = 65 ;
}
else
{
TheStu[i].grade = 60 ;
}
cout<<TheStu[i].grade<<endl;
}
if ( i == StuNumber - 1 )
{
cout<<endl;
}
}//for
}//while
return 0 ;
}
void GetMin(stu* student)
{
if ( student->p == 4 )
{
if ( strcmp(student->time,min4) < 0) //输入时间更短
{
strcpy(min4,student->time);
}
}
else
if ( student->p == 3 )
{
if ( strcmp(student->time,min3) < 0) //输入时间更短
{
strcpy(min3,student->time);
}
}
else
if ( student->p == 2 )
{
if ( strcmp(student->time,min2) < 0) //输入时间更短
{
strcpy(min2,student->time);
}
}
else
{
if ( strcmp(student->time,min1) < 0) //输入时间更短
{
strcpy(min1,student->time);
}
}
}
[解决办法]
参考下这个:
http://hi.baidu.com/qiaolw/item/7268d718d71b084a6926bb15