UVA 10194 Football (aka Soccer)

本文介绍了一个用于分析足球比赛情况的程序设计,该程序能够处理输入的比赛数据,并根据得分、胜负等因素来确定各参赛队伍的排名。具体实现包括读取比赛结果、计算积分和排名逻辑等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


 

 Problem A: Football (aka Soccer) 

 

 

The Problem

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.

The 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.

The 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)
题意: 足球比赛。。给定球队。和比赛的情况。比赛为 队伍1 #队伍1赢球数 @ 队伍2赢球数 # 队伍2 这样的格式。
赢一场得3分 平一场得1分 输了不得分。
最后要输出整个比赛的情况。。(排名 队名 得分 总场次 赢场 平场 输场 净胜球 胜球数 输球数)
注意的一点、整个比赛的情况要按 得分 -》 赢场 -》 净胜球 -》 胜球数 -》总场次少的 -》 队名字典序(不分大小写) 排序输出。。。
思路: 就是字符串处理稍微麻烦。。。其实挺水的 
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
char cn[105];
int tnum;
int cnum;
int tt;
struct Team
{
    char name[35];
    int f;
    int z;
    int y;
    int s;
    int p;
    int zq;
    int yq;
    int sq;
} t[35];

int find(char *team)
{
    for (int i = 0; i < tnum; i ++)
    {
	if(strcmp(t[i].name, team) == 0)
	{
	    return i;
	}
    }
    return -1;
}

int cmp(Team a, Team b)
{
    if (a.f == b.f)
    {
	if (a.y == b.y)
	{
	    if (a.zq == b.zq)
	    {
		if (a.yq == b.yq)
		{
		    if (a.z == b.z)
		    {
			if (strcasecmp(a.name, b.name) < 0)
			    return 1;
			if (strcasecmp(a.name, b.name) > 0)
			    return 0;
		    }
		    else
			return a.z < b.z;
		}
		else
		    return a.yq > b.yq;
	    }
	    else
		return a.zq > b.zq;
	}
	else
	    return a.y > b.y;
    }
    else
	return a.f > b.f;	
}

int main()
{
    scanf("%d", &tt);
    getchar();
    while (tt --)
    {
	gets(cn);
	memset(t, 0, sizeof(t));
	scanf("%d", &tnum);
	getchar();
	for (int i = 0; i < tnum; i ++)
	    gets(t[i].name);
	scanf("%d", &cnum);
	getchar();
	while (cnum --)
	{
	    char t1[35];
	    int t1num = 0;
	    int t1y = 0;
	    char t2[35];
	    int t2num = 0;
	    int t2y = 0;
	    char sb;
	    while ((sb = getchar()) != EOF)
	    {
		if (sb == '#')
		    break;
		t1[t1num ++] = sb;
	    }
	    t1[t1num] = '\0';
	    while ((sb = getchar()) != EOF)
	    {
		if (sb == '@')
		    break;
		t1y = t1y * 10 + sb - '0';
	    }
	    while ((sb = getchar()) != EOF)
	    {
		if (sb == '#')
		    break;
		t2y = t2y * 10 + sb - '0';
	    }
	    while ((sb = getchar()) != EOF)
	    {
		if (sb == '\n')
		    break;
		t2[t2num ++] = sb;
	    }
	    t2[t2num] = '\0';
	    int t11 = find(t1);
	    int t22 = find(t2);
	    t[t11].yq += t1y;
	    t[t11].sq += t2y;
	    if (t1y > t2y)
		t[t11].y ++;
	    else if(t1y < t2y)
		t[t11].s ++;
	    else
		t[t11].p ++;
	    t[t22].yq += t2y;
	    t[t22].sq += t1y;
	    if (t1y > t2y)
		t[t22].s ++;
	    else if(t1y < t2y)
		t[t22].y ++;
	    else
		t[t22].p ++;
	}
	for (int i = 0; i < tnum; i ++)
	{
	    t[i].f = t[i].y * 3 + t[i].p;
	    t[i].z = t[i].y + t[i].p + t[i].s;
	    t[i].zq = t[i].yq - t[i].sq;
	}
	sort(t, t + tnum, cmp);
	printf("%s\n", cn);
	for (int i = 0; i < tnum; i ++)
	    printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n",i + 1, t[i].name, t[i].f, t[i].z, t[i].y, t[i].p, t[i].s, t[i].zq, t[i].yq, t[i].sq);
	if (tt)
	    printf("\n");
    }
    return 0;
}


 

内容概要:本文探讨了在MATLAB/SimuLink环境中进行三相STATCOM(静态同步补偿器)无功补偿的技术方法及其仿真过程。首先介绍了STATCOM作为无功功率补偿装置的工作原理,即通过调节交流电压的幅值和相位来实现对无功功率的有效管理。接着详细描述了在MATLAB/SimuLink平台下构建三相STATCOM仿真模型的具体步骤,包括创建新模型、添加电源和负载、搭建主电路、加入控制模块以及完成整个电路的连接。然后阐述了如何通过对STATCOM输出电压和电流的精确调控达到无功补偿的目的,并展示了具体的仿真结果分析方法,如读取仿真数据、提取关键参数、绘制无功功率变化曲线等。最后指出,这种技术可以显著提升电力系统的稳定性与电能质量,展望了STATCOM在未来的发展潜力。 适合人群:电气工程专业学生、从事电力系统相关工作的技术人员、希望深入了解无功补偿技术的研究人员。 使用场景及目标:适用于想要掌握MATLAB/SimuLink软件操作技能的人群,特别是那些专注于电力电子领域的从业者;旨在帮助他们学会建立复杂的电力系统仿真模型,以便更好地理解STATCOM的工作机制,进而优化实际项目中的无功补偿方案。 其他说明:文中提供的实例代码可以帮助读者直观地了解如何从零开始构建一个完整的三相STATCOM仿真环境,并通过图形化的方式展示无功补偿的效果,便于进一步的学习与研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值