Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
一次ac,不过用的是vector过的。#include <iostream> #include <vector> #include <algorithm> #include <cstring> #include <cmath> #include <string> using namespace std; struct player{ string name; int solved; int penalty; }; bool lesscmp(const player& p1,const player& p2) { return p1.penalty < p2.penalty; } int main() { vector<player> players; int i,n,max_sub=0; cin>>n; for(i=0;i<n;i++) { player temp; cin>>temp.name; int prob,pena,j,all_sub=0,all_pena=0; for(j=0;j<4;j++) { cin>>prob>>pena; if(pena>0) { all_sub++; all_pena+=(prob-1)*20+pena; } } temp.solved=all_sub; temp.penalty=all_pena; players.push_back(temp); if(all_sub>max_sub) max_sub=all_sub; } vector<player>::iterator det; for(det=players.begin();det!=players.end();) { if(det->solved<max_sub) players.erase(det); else det++; } sort(players.begin(),players.end(),lesscmp); cout<<players[0].name<<" "<<max_sub<<" "<<players[0].penalty; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator