4 5 25 10 10 12 13 15 CS004 3 5 1 3 CS003 5 2 4 1 3 5 CS002 2 1 2 CS001 3 2 3 5 1 2 40 10 30 CS001 1 2 2 3 20 10 10 10 CS000000000000000001 0 CS000000000000000002 2 1 2 0
3 CS003 60 CS001 37 CS004 37 0 1 CS000000000000000002 20HintHuge input, scanf is recommended.挺简单 ,按照他说的来 就ok。注意某些数据类型AC Code:#include<iostream> #include<string> #include<algorithm> using namespace std; struct person { string str; int n; int t[11];//保存考试题号 double score; }per[1001]; bool cmp(person T,person A) { if(T.score!=A.score) return T.score>A.score; else return T.str<A.str; } int main() { int N,st;//st表示解决的题目总数 double scline;//分数线 while(cin>>N>>st>>scline,N) { for(int p=0;p<N;p++)//每次测试重置score per[p].score=0; double *persc=new double[10001];//记录每道题目的分值 for(int i=1;i<=st;i++) { cin>>persc[i]; } for(int j=0;j<N;j++) { cin>>per[j].str>>per[j].n; for(int k=1;k<=per[j].n;k++)//表示输入结局的题号 cin>>per[j].t[k]; for(int q=1;q<=per[j].n;q++) per[j].score+=persc[per[j].t[q]]; } sort(per,per+N,cmp); int *temp=new int [1001];int x=0;//记录满足条件的结构对象 for(int t=0;t<N;t++) { if(per[t].score>=scline) temp[x++]=t; } cout<<x<<endl; for(int g=0;g<x;g++) { cout<<per[temp[g]].str<<" "<<per[temp[g]].score<<endl; } } return 0; }
原文地址:http://blog.csdn.net/lsgqjh/article/details/44818701