uva 10194 Football (aka Soccer)

来源:互联网 发布:seo专员工作内容 编辑:程序博客网 时间:2024/04/29 10:16

                    uva 10194 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

2World Cup 1998 - Group A4BrazilNorwayMoroccoScotland6Brazil#2@1#ScotlandNorway#2@2#MoroccoScotland#1@1#NorwayBrazil#3@0#MoroccoMorocco#3@0#ScotlandBrazil#1@2#NorwaySome strange tournament5Team ATeam BTeam CTeam DTeam E5Team A#1@1#Team BTeam A#2@2#Team CTeam A#0@0#Team DTeam E#2@1#Team CTeam E#1@2#Team D

Sample Output

World Cup 1998 - Group A1) 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 tournament1) 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)


题目大意:给出一场足球比赛(记得名称),有n个球队,m次对抗,(team 1#进球数@进球数#team 2),任务,输出球队排名,按照:

1、得分数;

2、获胜场次;

3、最大净进球;

4、最多进球;

5、最少比赛;

6、队名的字典序(无大小写区别);

输出:队名 得分p 场次g, (获胜-平局-失败), 净进球(进球数-失球数)

解题思路:这题比较繁琐,要注意很多细节,字符串的题目就是这样, 一个不小心就出错。首先是读入数据,这很简单,然后是处理数据,难点和重点就在这里。主要需要处理的是比赛情况,我设置了一个结构体来存储队名,胜负情况,进球丢球情况。这题还有个重点是排序,可以用sort或者qsort,不要学我,我是自己写的……因为不大会用……

#include<stdio.h>#include<stdlib.h>#include<string.h>#include<cctype>struct team {                       //队伍情况结构体char tn[1000];int get = 0, drop = 0, win = 0, lost = 0, tie = 0; };void strlow(char *s) {   //大写变小写int len = strlen(s);for (int i = 0; i < len; i++) {if (s[i] >= 'A' && s[i] <= 'Z') {s[i] += 32;}}}int compare(team &a,team &b) {   //对比函数,对比完之后直接交换team temp;if (a.win * 3 + a.tie < b.win * 3 + b.tie) {temp = a;a = b;b = temp;return 0;}if (a.win * 3 + a.tie == b.win * 3 + b.tie) {if (a.win < b.win) {temp = a;a = b;b = temp;return 0;} if (a.win == b.win) {if (a.get - a.drop < b.get - b.drop) {temp = a;a = b;b = temp;return 0;}if (a.get - a.drop == b.get - b.drop) {if (a.get < b.get) {temp = a;a = b;b = temp;return 0;}if (a.get == b.get) {if (a.win + a.tie + a.lost > b.win + b.tie + b.lost) {temp = a;a = b;b = temp;return 0;}if (a.win + a.tie + a.lost == a.win + a.tie + a.lost) {char aa[1000],bb[1000];memset(aa, 0, sizeof(aa));memset(bb, 0, sizeof(bb));strcpy(aa, a.tn);strcpy(bb, b.tn);strlow(aa);strlow(bb);if (strcmp(aa,bb) > 0) {temp = a;a = b;b = temp;return 0;}}}}}}}void sort(team *t, int len) {         //土的掉渣,后期用不到的,冒泡排序for (int i = 0; i < len - 1; i++) {for (int j = 0; j < len - 1 - i; j++) {compare(t[j],t[j+1]);}}}char s2[1005][5000];int main() {int N;scanf("%d\n", &N);while (N--) {char s[2000];memset(s, 0, sizeof(s));gets(s);printf("%s\n", s);int M, cnt1 = 0;team t[1000];scanf("%d\n", &M);while (M--) {memset(t[cnt1].tn, 0, sizeof(t[cnt1].tn));gets(t[cnt1].tn);cnt1++;}int L, cnt2 = 0;memset(s2, 0, sizeof(s2));scanf("%d\n", &L);while (L--) {gets(s2[cnt2++]);}for (int i = 0; i < cnt2; i++) {        //处理比赛情况char temp[2][5000], score[2][30];int flag = 0;int tnum = 0, cnt3 = 0, cnt4 = 0;memset(temp, 0, sizeof(temp));memset(score, 0, sizeof(score));int len = strlen(s2[i]);int j  = 0;while (s2[i][j] != '#') {temp[tnum][cnt3++] = s2[i][j];j++;}j++;while (s2[i][j] >= '0' && s2[i][j] <= '9') {score[tnum][cnt4++] = s2[i][j];j++;}tnum++;cnt4 = 0;j++;while (s2[i][j] >= '0' && s2[i][j] <= '9') {score[tnum][cnt4++] = s2[i][j];j++;}j++;cnt3 = 0;while (s2[i][j] != NULL) {temp[tnum][cnt3++] = s2[i][j];j++;}int sco[2] = {0, 0};sco[0] = atoi(score[0]);sco[1] = atoi(score[1]);int num1, num2;for (int k = 0; k < cnt1; k++) {if (strcmp(temp[0], t[k].tn) == 0) {num1 = k;}if (strcmp(temp[1], t[k].tn) == 0) {num2 = k;}}t[num1].get += sco[0];t[num1].drop += sco[1];t[num2].get += sco[1];t[num2].drop += sco[0];if (sco[0] > sco[1]) {t[num1].win++;t[num2].lost++;}else if (sco[0] == sco[1]) {t[num1].tie++;t[num2].tie++;}else {t[num1].lost++;t[num2].win++;}}sort(t,cnt1);    //排序for (int i = 0; i < cnt1; i++) {printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", i+1, t[i].tn, t[i].win * 3 + t[i].tie, t[i].win + t[i].tie + t[i].lost, t[i].win, t[i].tie, t[i].lost, t[i].get - t[i].drop, t[i].get, t[i].drop);}                        //懒人的输出if (N) {printf("\n");}}return 0;}





0 0
原创粉丝点击