lunes, 24 de octubre de 2011

Problem A: Football (aka Soccer) , uva

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<cctype>
#include<cmath>
#include<vector>
#include<algorithm>
#define db(a) cout << #a << " = " << a << endl;
#define db2(a, b) cout << #a << " = " << a << "  " << #b << " = " << b << endl;
#define foreach(it, l) for(typeof(l.begin()) it = l.begin(); it != l.end(); it++)
using namespace std;
struct team{
string name;
int total_points;
int games_played;
int wins;
int ties;
int losses;
int goal_scored;
int goal_against;
};
bool cmp(team a, team b){
	if (a.total_points > b.total_points) 
		return true;
	else {
		if (a.total_points == b.total_points){
			if(a.wins > b.wins) 
				return true;
			else {
					if (a.wins == b.wins) {
						if ((a.goal_scored - a.goal_against) > (b.goal_scored - b.goal_against))
							return true;
						else {
								if ((a.goal_scored - a.goal_against) == (b.goal_scored - b.goal_against)) {
									if (a.goal_scored > b.goal_scored)
										return true;
									else {
											if (a.goal_scored == b.goal_scored) {
												if (a.games_played < b.games_played)
													return true;
												else {
													if (a.games_played == b.games_played) {
														if (strcasecmp(a.name.c_str(), b.name.c_str()) <= 0)
															return true;
														else 
															return false;
													}
													else 
														return false;
												}
											}
											else
												return false;
										}
								}
								else
									return false;
							}
					}
					else {
						return false;
					}
			}
		}
		else {
			return false;
		}
	}
}
int main(){
	int N, T, G, ptosA, ptosB;
	string teamA, teamB;
	string tournament;
	string linea;
	scanf("%d\n", &N);
	for (int cases = 0; cases < N; cases++) {
		if(cases != 0) printf("\n");
		getline(cin , tournament, '\n');
		scanf("%d\n", &T);
		team equipos[T];
		for (int i = 0; i < T; i++) {
			getline(cin, equipos[i].name, '\n');
			//db(equipos[i].name);
			equipos[i].total_points = 0;equipos[i].games_played = 0;
			equipos[i].wins = 0;equipos[i].ties = 0;equipos[i].losses = 0;
			equipos[i].goal_scored = 0;equipos[i].goal_against = 0;
		}
		scanf("%d\n", &G);
		for (int i = 0; i < G; i++) {
			getline(cin, linea , '\n');
			//db(linea);
			char *st, *buf, sep[] = "#@";
			buf = strdup(linea.c_str());
			st = strtok(buf, sep);
			teamA = st;
			st = strtok(0, sep);
			ptosA = atoi(st);
			st = strtok(0, sep);
			ptosB = atoi(st);
			st = strtok(0, sep);
			teamB = st;
			/*db2(teamA, ptosA);
			db2(teamB, ptosB);*/
			for (int k = 0; k < T; k++){
				if(equipos[k].name == teamA){
					if(ptosA > ptosB) equipos[k].wins++, equipos[k].total_points += 3;
					if(ptosA == ptosB) equipos[k].ties++, equipos[k].total_points++;
					if(ptosA < ptosB) equipos[k].losses++;
					equipos[k].games_played++;
					equipos[k].goal_scored += ptosA;
					equipos[k].goal_against += ptosB;
				}
				if(equipos[k].name == teamB){
					if(ptosB > ptosA) equipos[k].wins++, equipos[k].total_points += 3;
					if(ptosB == ptosA) equipos[k].ties++, equipos[k].total_points++;
					if(ptosB < ptosA) equipos[k].losses++;
					equipos[k].games_played++;
					equipos[k].goal_scored += ptosB;
					equipos[k].goal_against += ptosA;
				}
			}
		}
		sort(equipos, equipos + T, cmp);
		printf("%s\n", tournament.c_str());
		for (int k = 0; k < T; k++) {
			printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", k + 1, equipos[k].name.c_str(), equipos[k].total_points, equipos[k].games_played, equipos[k].wins, equipos[k].ties, equipos[k].losses, (equipos[k].goal_scored - equipos[k].goal_against), equipos[k].goal_scored, equipos[k].goal_against);
		}
	}
	
}


No hay comentarios:

Publicar un comentario