and you can do better by making a better comparison function.
//
// main.cpp
// 10258 - Contest Scoreboard
//
// Created by Panks on 31/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cstdio>
using namespace std;
struct info {
int id;
int problems[12];
int penalty[12];
int tsolved;
int time;
};
bool cmp(info a, info b);
bool cmp(info a, info b){
if (a.tsolved<b.tsolved) {
return false;
}else if(a.tsolved>b.tsolved){
return true;
}else{
if (a.penalty[11]<b.penalty[11]) {
return true;
}else if(a.penalty[11]>b.penalty[11]){
return false;
}else{
return (a.id-b.id)<0;
}
}
}
int main (int argc, const char * argv[])
{
vector<info> store;
int t,contestant,problem,time;
string L;
string input;
stringstream ss;
cin>>t;
getchar();
info data;
data.id=0; fill_n(data.problems,12, 0);
fill_n(data.penalty,12, 0); data.time=0, data.tsolved=0;;
getchar();
while (t--) {
getline(cin,input);
store.resize(101);
fill_n(store.begin(), 101, data);
while (input!="") {
ss.str(input);
ss>>contestant; ss>>problem; ss>>time; ss>>L;
if (!L.compare("C")) {
store[contestant].id=contestant;
if (store[contestant].problems[problem]==0) {
store[contestant].problems[problem]=1;
store[contestant].penalty[problem]+=time;
}
}else if (!L.compare("I")) {
store[contestant].id=contestant;
if (store[contestant].problems[problem]==0) {
store[contestant].penalty[problem]+=20;
}
}else{
store[contestant].id=contestant;
}
getline(cin, input);
ss.clear();
}
for (int i=0; i<store.size(); i++) {
for (int j=0; j<10; j++) {
if (store[i].problems[j]) {
store[i].tsolved++;
store[i].penalty[11]+=store[i].penalty[j];
}
}
}
sort(store.begin(), store.end(), cmp);
for (int i=0; i<store.size(); i++) {
if (store[i].id==0) {
continue;
}
cout<<store[i].id<<" "<<store[i].tsolved<<" "<<store[i].penalty[11]<<endl;
}
if (t!=0) {
cout<<endl;
}
store.clear();
ss.clear();
}
return 0;
}

No comments:
Post a Comment