Skip to content

Instantly share code, notes, and snippets.

@ernestognw
Created September 3, 2019 00:11
Show Gist options
  • Save ernestognw/1bb95a050ac9c55fa43b44cc0baa0a74 to your computer and use it in GitHub Desktop.
Save ernestognw/1bb95a050ac9c55fa43b44cc0baa0a74 to your computer and use it in GitHub Desktop.
// icpScore
// Ernesto García A00820783
// Created at Mon Sep 2 18:00:11 CDT 2019
#include<iostream>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<string>
using namespace std;
struct Team {
string name;
int time;
int solved;
unordered_map<char, int> submissions;
Team() : time(0), solved(0) {};
};
bool compareTeams(Team t1, Team t2){
if(t1.solved == t2.solved){
return t1.time < t2.time;
}
return t1.solved > t2.solved;
}
int main() {
int teamsQty, problemsQty, submissionsQty;
cin >> teamsQty;
cin >> problemsQty;
vector<Team> teams(teamsQty);
unordered_map<string, int> indexedNames;
for(int i = 0; i < teamsQty; i++){
Team team;
cin >> team.name;
teams[i] = team;
indexedNames[team.name] = i;
}
cin >> submissionsQty;
for(int i = 0; i < submissionsQty; i++){
string teamName;
char problem;
int time;
char status;
cin >> teamName;
cin >> problem;
cin >> time;
cin >> status;
int indexOfTeam = indexedNames[teamName];
if(status == 'W'){
teams[indexOfTeam].submissions[problem]++;
} else {
int penalization = teams[indexOfTeam].submissions[problem] * 20;
teams[indexOfTeam].time += time + penalization;
teams[indexOfTeam].solved++;
}
}
sort(teams.begin(), teams.end(), compareTeams);
for(int i = 0; i < teams.size(); i++){
cout << i + 1 << " - " << teams[i].name << " " << teams[i].solved << " ";
teams[i].time > 0 ? cout << teams[i].time : cout << '-';
cout << endl;
}
// End program
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment