UVA 10194 Football (aka Soccer) 足球成绩统计 检索+模拟

题意:先读入球队信息,再按“team_name_1#goals1@goals2#team_name_2”的格式读入球队的比赛情况,然后统计各个球队的比赛得分,进球数,丢球数等等各项指标。最后按题目给定的顺序输出各个球队的信息。

这题一个非常坑的地方就是在排序时队名的排序是按小写排的,看了别人博客上提醒才发现有这回事。。。

还有一个我被坑很久的就是球队的排序不是各指标全部都是从排的。。。这里wa无数次,实在令人羞愧。。。

这里读入球队信息的时候有个小trick,可以用scanf("%d@%d", &goals1, &goals2)这样去读入中间那快数据会更方便(虽然方便不了多少)。。。

代码:

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cctype>
using namespace std;

struct Table {
	int tp, g, w, t, l, h, i;
	string n;
}tb[50];

bool cmp(Table a, Table b) {
	if (a.tp != b.tp)
		return a.tp > b.tp;
	if (a.w != b.w)
		return a.w > b.w;
	if ((a.h - a.i) != (b.h - b.i))
		return (a.h - a.i) > (b.h - b.i);
	if (a.h != b.h)
		return a.h > b.h;
	if (a.g != b.g)
		return a.g < b.g;
	string ta, tb;
	for (int i = 0; i < a.n.size(); i++)
		ta += toupper(a.n[i]);
	for (int i = 0; i < b.n.size(); i++)
		tb += toupper(b.n[i]);
	return ta < tb;
}

int main() {
	int n;
	scanf("%d", &n);
	getchar();
	while (n--) {
		string name;
		int t, g;
		getline(cin, name);
		cout << name << endl;
		scanf("%d\n", &t);
		for (int i = 0; i < t; i++) {
			getline(cin, tb[i].n);
			tb[i].tp = tb[i].g = tb[i].w = tb[i].t = tb[i].l = tb[i].h = tb[i].i = 0;
		}
		scanf("%d\n", &g);
		for (int i = 0; i < g; i++) {
			string t1, t2;
			int n1, n2;
			int s1, s2;
			char tmp;
			while ((tmp = getchar()) != '#')
				t1 += tmp;
			scanf("%d@%d#", &s1, &s2);
			getline(cin, t2);
			for (int i = 0; i < t; i++)
				if (t1 == tb[i].n) {
					n1 = i;
					break;
				}
			for (int i = 0; i < t; i++)
				if (t2 == tb[i].n) {
					n2 = i;
					break;
				}
			//			cout << n1 << ' ' << s1 << ' ' << t1 << endl;
			//			cout << n2 << ' ' << s2 << ' ' << t2 << endl;
			tb[n1].g++;
			tb[n2].g++;
			tb[n1].h += s1;
			tb[n1].i += s2;
			tb[n2].h += s2;
			tb[n2].i += s1;
			if (s1 > s2) {
				tb[n1].tp += 3;
				tb[n1].w++;
				tb[n2].l++;
			}
			else if (s1 < s2) {
				tb[n2].tp += 3;
				tb[n2].w++;
				tb[n1].l++;
			}
			else {
				tb[n1].tp++;
				tb[n2].tp++;
				tb[n1].t++;
				tb[n2].t++;
			}
		}
		sort (tb, tb + t, cmp);
		for (int i = 0; i < t; i++) {
			printf("%d) ", i + 1);
			cout << tb[i].n;
			printf(" %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", tb[i].tp, tb[i].g, tb[i].w, tb[i].t, tb[i].l, tb[i].h - tb[i].i, tb[i].h, tb[i].i);
		}
		if (n)
			cout << endl;
	}
	return 0;
}


你可能感兴趣的:(ACM)