I keep getting WA about this problem (although it sounds to be one of those straight forward problem). Is there some tricky test cases about this problem? If yes please post some along with their output. Thanks!

Moderator: Board moderators
Code: Select all
2 0
B
a
Code: Select all
1. a 0 0 0 0 0 N/A
B 0 0 0 0 0 N/A
Code: Select all
My output format is:
if I am printing team position: printf("%2d.%16s%4d%4d%4d%4d%4d "); etc etc...
else printf("%19s%4d%4d%4d%4d%4d "); etc....
(I added the percentage later)
Code: Select all
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <algorithm>
#include <sstream>
#include <set>
#include <climits>
#include <cstdio>
#include <string>
#include <map>
#include <unordered_map>
#ifndef ONLINE_JUDGE
#define getc_unlocked getc
#define putc_unlocked putc
#endif
using namespace std;
struct Team {
string name;
int scored = 0;
int suffered = 0;
int points = 0;
int played = 0;
int difference = 0;
int idx = 0;
};
int getpoints(int goal1, int goal2) {
if (goal1 == goal2)
return 1;
else if (goal1 > goal2)
return 3;
return 0;
}
bool compare(Team team1, Team team2) {
if (team1.points > team2.points)
return true;
else if (team1.points == team2.points) {
if (team1.difference > team2.difference)
return true;
else if (team1.difference == team2.difference) {
if (team1.scored > team2.scored)
return true;
else if (team1.scored == team2.scored) {
transform(team1.name.begin(), team1.name.end(), team1.name.begin(), ::tolower);
transform(team2.name.begin(), team2.name.end(), team2.name.begin(), ::tolower);
if (team1.name <= team2.name)
return true;
return false;
}
return false;
}
return false;
}
return false;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("1.txt", "r", stdin);
freopen("2.txt", "w", stdout);
#endif
register int g, t;
string str;
register int goal1, goal2;
char c;
cin >> g >> t;
while (g || t) {
map<string, int> teamMap;
vector<Team> teamList;
int idx = 0;
while (g--) {
cin >> str;
Team team; team.name = str; team.idx = idx;
teamList.push_back(team);
teamMap[str] = idx++;
}
while (t--) {
cin >> str >> goal1 >> c >> goal2;
Team & team = teamList[teamMap[str]];
team.scored += goal1;
team.suffered += goal2;
team.points += getpoints(goal1, goal2);
team.played++; team.difference = team.scored - team.suffered;
cin >> str;
Team &team1 = teamList[teamMap[str]];
team1.scored += goal2;
team1.suffered += goal1;
team1.points += getpoints(goal2, goal1);
team1.played++; team1.difference = team1.scored - team1.suffered;
}
stable_sort(teamList.begin(), teamList.end(), compare);
double result = 0.0f;
char na[] = "N/A";
for (int i = 1; i <= (int)teamList.size(); i++) {
result = ((double(teamList[i - 1].points)) / (double(teamList[i - 1].played * 3))) * (double(100));
if (i - 2 >= 0) {
if ((teamList[i - 1].points == teamList[i - 2].points) && (teamList[i - 1].difference == teamList[i - 2].difference) && (teamList[i - 1].scored == teamList[i - 2].scored))
printf("%19s%4d%4d%4d%4d%4d ", teamList[i - 1].name.c_str(), teamList[i - 1].points, teamList[i - 1].played, teamList[i - 1].scored, teamList[i - 1].suffered, teamList[i - 1].difference);
else
printf("%2d.%16s%4d%4d%4d%4d%4d ", i, teamList[i - 1].name.c_str(), teamList[i - 1].points, teamList[i - 1].played, teamList[i - 1].scored, teamList[i - 1].suffered, teamList[i - 1].difference);
} else
printf("%2d.%16s%4d%4d%4d%4d%4d ", i, teamList[i - 1].name.c_str(), teamList[i - 1].points, teamList[i - 1].played, teamList[i - 1].scored, teamList[i - 1].suffered, teamList[i - 1].difference);
if (result != result)
printf("%6s\n", na);
else
printf("%6.2f\n", result);
}
cin >> g >> t;
if (g != 0 && t != 0)
printf("\n");
}
}