uva 10194(排序、检索)

题目:

Football the most popular sport in the world (americans insist to call it "Soccer", but we will call it "Football"). As everyone knows, Brasil is the country that have most World Cup titles (four of them: 1958, 1962, 1970 and 1994). As our national tournament have many teams (and even regional tournaments have many teams also) it's a very hard task to keep track of standings with so many teams and games played!

So, your task is quite simple: write a program that receives the tournament name, team names and games played and outputs the tournament standings so far.

A team wins a game if it scores more goals than its oponent. Obviously, a team loses a game if it scores less goals. When both teams score the same number of goals, we call it a tie. A team earns 3 points for each win, 1 point for each tie and 0 point for each loss.

Teams are ranked according to these rules (in this order):

    1.  Most points earned.
    2. Most wins.
    3.Most goal difference (i.e. goals scored - goals against)
    4. Most goals scored.
    5. Less games played.
    6. Lexicographic order. 

input

 The first line of input will be an integer N in a line alone (0 < N < 1000). Then, will follow N tournament descriptions. Each one begins with the tournament name, on a single line. Tournament names can have any letter, digits, spaces etc. Tournament names will have length of at most 100. Then, in the next line, there will be a number T (1 < T <= 30), which stands for the number of teams participating on this tournament. Then will follow T lines, each one containing one team name. Team names may have any character that have ASCII code greater than or equal to 32 (space), except for '#' and '@' characters, which will never appear in team names. No team name will have more than 30 characters.

Following to team names, there will be a non-negative integer G on a single line which stands for the number of games already played on this tournament. G will be no greater than 1000. Then, G lines will follow with the results of games played. They will follow this format:

team_name_1#goals1@goals2#team_name_2

For instance, the following line:

Team A#3@1#Team B

Means that in a game between Team A and Team B, Team A scored 3 goals and Team B scored 1. All goals will be non-negative integers less than 20. You may assume that there will not be inexistent team names (i.e. all team names that appear on game results will have apperead on the team names section) and that no team will play against itself.

output
For each tournament, you must output the tournament name in a single line. In the next T lines you must output the standings, according to the rules above. Notice that should the tie-breaker be the lexographic order, it must be done case insenstive. The output format for each line is shown bellow:

[a]) Team_name [b]p, [c]g ([d]-[e]-[f]), [g]gd ([h]-[i])

Where:

    [a] = team rank
    [b] = total points earned
    [c] = games played
    [d] = wins
    [e] = ties
    [f] = losses
    [g] = goal difference
    [h] = goals scored
    [i] = goals against

There must be a single blank space between fields and a single blank line between output sets. See the sample output for examples.

sample input

2
World Cup 1998 - Group A
4
Brazil
Norway
Morocco
Scotland
6
Brazil#2@1#Scotland
Norway#2@2#Morocco
Scotland#1@1#Norway
Brazil#3@0#Morocco
Morocco#3@0#Scotland
Brazil#1@2#Norway
Some strange tournament
5
Team A
Team B
Team C
Team D
Team E
5
Team A#1@1#Team B
Team A#2@2#Team C
Team A#0@0#Team D
Team E#2@1#Team C
Team E#1@2#Team D

sample output

World Cup 1998 - Group A
1) Brazil 6p, 3g (2-0-1), 3gd (6-3)
2) Norway 5p, 3g (1-2-0), 1gd (5-4)
3) Morocco 4p, 3g (1-1-1), 0gd (5-5)
4) Scotland 1p, 3g (0-1-2), -4gd (2-6)

Some strange tournament
1) Team D 4p, 2g (1-1-0), 1gd (2-1)
2) Team E 3p, 2g (1-0-1), 0gd (3-3)
3) Team A 3p, 3g (0-3-0), 0gd (3-3)
4) Team B 1p, 1g (0-1-0), 0gd (1-1)
5) Team C 1p, 2g (0-1-1), -1gd (3-4)

题解:输入比赛名称,队伍数量,队伍名称,比赛场数,比赛情况。输出排名+队名+得分(胜得三分,平得一分,负没分)+参赛场数(胜 -平-负) 净进球(进球-失球)

排名是按得分计算,如果得分相同,按胜场,如果胜场相同,类比按净进球,然后是进球,然后是参赛场数(从小到大),然后球队名(统一字母大小写)的字典序。


#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;
struct Team {
	string n;
	string nn;
	int point;//得分
	int played;//参赛场数
	int wins;//胜场数
	int ties;//平场数
	int losses;//输场数
	int diff;//净进球
	int scored;//进球
	int against;//失球
	Team () {
		point = played = wins = ties = losses = diff = scored = against = 0;
		n = nn = "";
	}
};
Team * fun(Team *t) {
		t->nn = t->n;
		int len = t->nn.size();
		for (int i = 0; i < len; i++)
			if(isalpha(t->nn[i]))
				t->nn[i] = toupper(t->nn[i]);
	return t;
}

int cmp (const void* t1, const void * t2) {
	if ((*(Team *)t1).point != (*(Team *)t2).point)//得分高的先输出
		return (*(Team *)t1).point < (*(Team *)t2).point;

	if ((*(Team *)t1).wins != (*(Team *)t2).wins)//胜场数高的先输出
		return (*(Team *)t1).wins < (*(Team *)t2).wins;

	if ((*(Team *)t1).diff != (*(Team *)t2).diff)//净进球数高的先输出
		return (*(Team *)t1).diff < (*(Team *)t2).diff;

	if ((*(Team *)t1).scored != (*(Team *)t2).scored)//进球数高的先输出
		return (*(Team *)t1).scored < (*(Team *)t2).scored;

	if ((*(Team *)t1).played != (*(Team *)t2).played)//参与场次少的先输出
		return (*(Team *)t1).played > (*(Team *)t2).played;
	t1 = fun((Team *)t1);
	t2 = fun((Team *)t2);
	return ((Team *)t1)->nn > ((Team *)t2)->nn;//先统一大小写然后按字典序输出
}

int main() {
	int t, cases, g, flag;
	string name, temp, str;
	char c;
	cin >> cases;
	getchar();
	while (cases--) {
		Team team[35];
		getline(cin, name);
		cout << name << endl;
		cin >> t;
		getchar();
		for (int i = 0; i < t; i++)
			getline(cin, team[i].n);
		cin >> g;
		getchar();
		int a = 0, k = 0,j = 0, b = 0;
		for (int i = 0; i < g; i++) {
			flag = 0;
			temp = "";
			while ((c = getchar()) != '#')
				temp += c;
			for (k = 0; k < t; k++)
				if (temp == team[k].n) {
					scanf("%d", &a);
					team[k].played++;
					break;
				}
			scanf("@%d#", &b);
			temp = "";
			while ((c = getchar()) != '\n')
				temp += c;
			for (j = 0; j < t; j++)
				if (temp == team[j].n) {
					team[j].played++;
					break;
				}	
			if (a > b) {
				team[k].point += 3;
				team[k].wins++;
				team[k].scored += a;
				team[k].against += b;
				team[j].losses++;
				team[j].scored += b;
				team[j].against += a;
			}
			if (a == b) {
				team[k].point += 1;
				team[k].ties++;
				team[k].scored += a;
				team[k].against += b;
				team[j].point += 1;
				team[j].ties++;
				team[j].scored += b;
				team[j].against += a;
			}
			if (a < b) {
				team[k].losses++;
				team[k].scored += a;
				team[k].against += b;
				team[j].point += 3;
				team[j].wins++;
				team[j].scored += b;
				team[j].against += a;
			}
		}
		for (int i = 0; i < t; i++)
			team[i].diff = team[i].scored - team[i].against;
		qsort(team, t, sizeof(team[0]), cmp);
		for (int i = 0; i < t; i++)
			cout << i + 1 << ") " << team[i].n << " " << team[i].point << "p, " << team[i].played << "g (" << team[i].wins << "-" << team[i].ties << "-" << team[i].losses << "), " << team[i].diff << "gd (" << team[i].scored << "-" << team[i].against << ")" << endl;
		if (cases)
			cout << endl;
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值