一直re,求大神解釋 題目:http://acm.hdu.edu.cn/showproblem.php?pid=1236
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct student
{
char kaohao[25];
int score;
};
bool cmp(student x,student y)
{
if(x.score!=y.score)return x.score>y.score;
else return strcmp(x.kaohao,y.kaohao)<=0;
}
int main()
{
int renshu,tishu,fenxian,ji;
student a[1005];
while(scanf("%d",&renshu) && renshu)
{
ji = 0;
memset(a,0,sizeof(a));
int count,tifen[25];
scanf("%d%d",&tishu,&fenxian);
for(int i = 1;i<=tishu;i++)
{
scanf("%d",&tifen[i]);
}
for(int i = 1;i<=renshu;i++)
{
getchar();
scanf("%s%d",a[i].kaohao,&count);
for(int j = 1;j<=count;j++)
{
int temp;
scanf("%d",&temp);
a[i].score += tifen[temp];
}
if(a[i].score>=fenxian)
ji++;
}
sort(a+1,a+renshu+1,cmp);
printf("%d\n",ji);
for(int i = 1;;i++)
{
if(a[i].score<fenxian)
{break;}
else printf("%s %d\n",a[i].kaohao,a[i].score);
}
}
}
最後輸出的時候,如果所有人都過線了,會造成數組越界的情況吧。
另外吐槽一下,這種中文拼音和英文單詞摻雜的寫法實在太喪病了