题意:按成绩排序
思路:排序
#include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struct node{ char name[25]; int grade; }a[1005]; bool cmp(node a,node b){ if(a.grade!=b.grade)return a.grade>b.grade;//降序 return strcmp(a.name,b.name)<0;//升序 } int main(){ int n,m,g,i; int sco[15]; int m2,num; int sum; while(~scanf("%d",&n)&&n){ memset(a,0,sizeof(a)); sum=0; scanf("%d%d",&m,&g); for(i=1;i<=m;++i) scanf("%d",&sco[i]); for(i=0;i<n;++i){ scanf("%s",a[i].name); scanf("%d",&m2); while(m2--){ scanf("%d",&num); a[i].grade+=sco[num]; } if(a[i].grade>=g)++sum; } sort(a,a+n,cmp); printf("%d\n",sum); for(i=0;i<n;++i){ if(a[i].grade<g)break; printf("%s %d\n",a[i].name,a[i].grade); } } return 0; }
时间: 2024-10-04 06:20:21