Problem - https://www.codechef.com/problems/UCL
My Solution - https://www.codechef.com/viewsolution/24937358
Why is my code giving WA? Any help is welcome. Thanks in Advance.
My Code :
#include <iostream>
#include <map>
#include <unordered_map>
#include <string>
#include <utility>
enum result{WIN = 3, TIE = 1, LOSS = 0};
struct compare{
bool operator() (const std::pair<int,int> &p1, const std::pair<int,int> &p2) const {
if (p1.first > p2.first) {
return true;
}
else if (p1.first == p2.first) {
return (p1.second >= p2.second);
}
else {
return false;
}
}
};
int main() {
int T;
std::cin >> T;
for (int i = 0; i < T; i++) {
std::unordered_map<std::string, std::pair<int,int> > table;
std::string Home, Away, Vs;
int s1, s2;
for (int i = 0; i < 12; i++) {
std::cin >> Home >> s1 >> Vs >> s2 >> Away;
enum result match;
if (s1 > s2) {
match = WIN;
}
else if (s1 == s2) {
match = TIE;
}
else {
match = LOSS;
}
auto i1 = table.find(Home);
auto i2 = table.find(Away);
if (i1 != table.end()) {
i1->second.first += match;
i1->second.second += s1-s2;
}
else {
table.emplace(Home,std::make_pair(match,s1-s2));
}
match == 1 ? :
match == 3 ? match = LOSS :
match = WIN;
if (i2 != table.end()) {
i2->second.first += match;
i2->second.second += s2-s1;
}
else {
table.emplace(Away,std::make_pair(match,s2-s1));
}
}
std::map<std::pair<int,int>,std::string,compare> sorted;
for (auto it = table.begin(); it != table.end(); it++) {
sorted.emplace(it->second,it->first);
}
auto it = sorted.begin();
std::cout << it->second << " " << (++it)->second << '\n';
}
return 0;
}