poj1236

结构体排序~水过
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
struct node
{
	char name[21];
	int all_score;
}c[1005];
bool cmp(node x,node y)
{
	if(x.all_score>y.all_score) return true;
	if(x.all_score==y.all_score&&strcmp(x.name,y.name)<0) return true;
	return false;
}
int main()
{
	int peo,test,per,sum,x,score[11],n,q;
	char name_peo[21];
	while(scanf("%d",&peo)&&peo)
	{
		scanf("%d %d",&test,&per);
		for(int i=0;i<test;i++)
		scanf("%d",&x),score[i]=x;
		q=0;
		for(int i=0;i<peo;i++)
		{
			scanf("%s %d",name_peo,&n);
			sum=0;
			for(int j=0;j<n;j++)
			{
				scanf("%d",&x);
				sum+=score[x-1];
			}
			if(sum>=per)
			strcpy(c[q].name,name_peo),
			c[q].all_score=sum,
			q++;
		}
		sort(c,c+q,cmp);
		printf("%d\n",q);
		for(int i=0;i<q;i++)
		printf("%s %d\n",c[i].name,c[i].all_score);
	}
	return 0;
}

你可能感兴趣的:(poj,1236,结构体排序,poj1236)