E-What Is You Grades?
这个主要是比较排序,但是还是要注意几个点,第一个是时间然后对排名靠前的处理
http://blog.csdn.net/a809146548/article/details/46352093
#include<cstdio> #include<algorithm> #include<cstring> using namespace std; struct node { int score; int num; char time[10]; } stu[101]; bool cmp(const node& a,const node& b) { if(a.num==b.num) return strcmp(a.time,b.time)<0; else return a.num>b.num; } int s[6][2]={50,50,60,65,70,75,80,85,90,95,100,100}; int main() { int n,i,x[6],j; char index[101][10]; while(scanf("%d",&n) &&n>0) { for(i=1;i<=n;i++) { scanf("%d%s",&stu[i].num,stu[i].time); strcpy(index[i],stu[i].time); } sort(stu+1,stu+n+1,cmp); memset(x,0,sizeof(x)); for(i=1;i<=n;i++) x[stu[i].num]++; for(i=1;i<=4;i++) if(x[i]!=1) x[i]/=2; for(i=1;i<=n;i++) if(x[stu[i].num]>0) { stu[i].score=s[stu[i].num][1]; x[stu[i].num]--; } else stu[i].score=s[stu[i].num][0]; for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(strcmp(index[i],stu[j].time)==0) { printf("%d\n",stu[j].score); break; } putchar('\n'); } return 0; }