ACCESS VIOLATION
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
int grade[20]={0};
typedef struct
{
string id;
int solved_total_num;
int solved_num[20];
int get_score;
}S;
S stu[1100];
void quick_sort1(int left,int right)
{
int i,j;
i=left;j=right;
if(left<right)
{
stu[0]=stu[i];
while(i!=j)
{
while(stu[0].id<stu[j].id && i<j) j--;
if(i<j)
{
stu[i]=stu[j];
i++;
}
while(stu[0].id>stu[i].id && i<j) i++;
if(i<j)
{
stu[j]=stu[i];
j--;
}
}
stu[i]=stu[0];
quick_sort1(left,i-1);
quick_sort1(i+1,right);
}
}
void quick_sort2(int left,int right)//score
{
int i,j;
i=left;j=right;
if(left<right)
{
stu[0]=stu[i];
while(i!=j)
{
while(stu[0].get_score>stu[j].get_score && i<j) j--;
if(i<j)
{
stu[i]=stu[j];
i++;
}
while(stu[0].get_score<stu[i].get_score && i<j) i++;
if(i<j)
{
stu[j]=stu[i];
j--;
}
}
stu[i]=stu[0];
quick_sort2(left,i-1);
quick_sort2(i+1,right);
}
}
int main()
{
int M,N,G,i,j,count,end,begin;//N考试人数,M是考题数,G是分数线。
while(scanf("%d",&N)!=EOF && N)
{
count=0;
scanf("%d%d",&M,&G);
for(i=1;i<=M;i++) scanf("%d",&grade[i]);
for(i=1;i<=N;i++)
{
stu[i].get_score=0;
cin>>stu[i].id;
scanf("%d",&stu[i].solved_total_num);
for(j=1;j<=stu[i].solved_total_num;j++)
{
scanf("%d",&stu[i].solved_num[j]);
stu[i].get_score+=grade[stu[i].solved_num[j]];
}
if(stu[i].get_score>=G) count++;
}
printf("%d\n",count);
quick_sort2(1,N);
i=1;
while(i<N)
{
if(stu[i].get_score==stu[i+1].get_score)
{
begin=i;
while(stu[i].get_score==stu[i+1].get_score) i++;
end=i;
quick_sort1(begin,end);
}
i++;
}
for(i=1;i<=N;i++)
{
if(stu[i].get_score>=G)
{
cout<<stu[i].id;
printf(" %d\n",stu[i].get_score);
}
}
}
return 0;
}
AC
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
int grade[22];
typedef struct
{
string id;
int solved_total_num;
int solved_num[22];
int get_score;
}S;
S stu[1010];
int comepare(S a,S b)
{
if(a.get_score!=b.get_score)
return a.get_score>b.get_score;
else if (a.id<b.id)
return 1;
else
return 0;
}
int main()
{
int M,N,G,i,j,count,end,begin;//N考试人数,M是考题数,G是分数线。
while(scanf("%d",&N)!=EOF && N)
{
count=0;
scanf("%d%d",&M,&G);
for(i=1;i<=M;i++) scanf("%d",&grade[i]);
for(i=1;i<=N;i++)
{
stu[i].get_score=0;
cin>>stu[i].id;
scanf("%d",&stu[i].solved_total_num);
for(j=1;j<=stu[i].solved_total_num;j++)
{
scanf("%d",&stu[i].solved_num[j]);
stu[i].get_score+=grade[stu[i].solved_num[j]];
}
if(stu[i].get_score>=G) count++;
}
printf("%d\n",count);
i=1;
sort(stu+1,stu+N+1,comepare);
for(i=1;i<=N;i++)
{
if(stu[i].get_score>=G)
{
cout<<stu[i].id;
printf(" %d\n",stu[i].get_score);
}
}
}
return 0;
}