考察排序,比较水的一题,加强一下对符号的重载,内用了stl处理,所以程序就变的相对简单了~~
#include <iostream> #include <algorithm> #include <stdio.h> #include <vector> using namespace std; struct stu { string s; int score; bool operator > (const stu m)const { if(score==m.score)return m.s > s; return score > m.score; } }; stu st[1005]; vector<stu>ans; int exam[15]; int n; void init() { int i; for(i=0; i<n; i++)st[i].score=0; ans.clear(); } int main() { while (~scanf("%d",&n)&&n) { init(); int m,g; scanf("%d%d",&m,&g); int i; for(i=1; i<=m; i++)scanf("%d",&exam[i]); for(i=0; i<n; i++) { cin>>st[i].s; int tm; scanf("%d",&tm); while(tm--) { int temp; scanf("%d",&temp); st[i].score+=exam[temp]; } if(st[i].score>=g)ans.push_back(st[i]); } sort( ans.begin(),ans.end(),greater<stu>() ); printf("%d\n",ans.size()); for(i=0; i<ans.size(); i++) { cout<<ans[i].s<<" "; printf("%d\n",ans[i].score); } } return 0; }