Rumah >pembangunan bahagian belakang >tutorial php >九度OnlineJudge之1014:排名_PHP教程
题目描述:
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <cstring> using namespace std; typedef struct persons { string id; int total; int grade; }persons; bool compare(persons a,persons b) { if (a.grade!=b.grade) return a.grade>b.grade; else return a.id < b.id; } int main() { int N,M,G; vector<persons> vec; int grade[11]; while(cin>>N,N!=0) { memset(grade,0,sizeof(grade)); vec.clear(); int ans=0; cin>>M>>G; for (int i=1;i<=M;i++) cin>>grade[i]; for (int i=0;i<N;i++) { persons p; cin>>p.id>>p.total; p.grade = 0; for (int j=1;j<=p.total;j++) { int t; cin>>t; p.grade += grade[t]; } if (p.grade >= G) ++ans; vec.push_back(p); } sort(vec.begin(),vec.end(),compare); cout<<ans<<endl; for (int i=0;i<ans;++i) { cout<<vec[i].id<<" "<<vec[i].grade<<endl; } } //system("pause"); return 0; }