HDU 1236 排序

/*

再水一题

sort()应用+strcmp()应用;

*/


http://acm.hdu.edu.cn/showproblem.php?pid=1236点击打开链接


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#define maxn 1005

struct student
{
	int grade;
	char name[21];
}stu[maxn];
int cmp(student s1, student s2)
{
	if(s1.grade>s2.grade)
		return 1;
	if(s1.grade == s2.grade)
	{
		if(strcmp(s1.name,s2.name)==-1)
			return 1;
		else
			return 0;
	}
	return 0;
}
using namespace std;
int main(int argc, char *argv[])
{
	int n, k, m,hmany;
	int M_g[11];
	while(scanf("%d",&n)&&n!=0)
	{
		scanf("%d%d",&m,&k);
		for(int i = 1; i <= m; i++)
			scanf("%d",&M_g[i]);
		int num,M_num;
		hmany = 0;   //hmany 存放超过分数线的人数
		for(int i = 0; i < n; i++)
		{
			stu[i].grade= 0;
			scanf("%s%d",stu[i].name,&num);
			for(int j = 0; j < num; j++)
			{
				scanf("%d",&M_num);
				stu[i].grade += M_g[M_num];
				//cout<<"stu"<<i<<": "<<stu[i].grade<<endl;
			}
			if(stu[i].grade >= k)
				hmany++;
		}
		
		sort(stu,stu+n,cmp);
	//	cout<<"*****"<<stu[1].grade<<endl;
		printf("%d\n",hmany);
		for(int i = 0; i < n; i++)
		{
			if(stu[i].grade >= k)
			printf("%s %d\n",stu[i].name,stu[i].grade);
		}
	}
	return 0;
}


posted @ 2013-03-06 19:07  简洁是智慧的灵魂  阅读(109)  评论(0)    收藏  举报