Football (aka soccer) ultraviolet A 10194

Source: Internet
Author: User

I never expected to spend so much time on this question. This question is actually complicated and requires a large structure to record all the information of a team. I thought the most difficult part was the extraction of the match result string, but it turns out to be quite simple. The key is to sort the results of the competition. The principle is relatively simple and the code is large. Note that sorting by team name is case-insensitive and the team name is not just an English letter! In addition, the C language features are mentioned here. If you call a function that returns a character pointer and returns a character array defined in the called function, an error will occur, this is because the corresponding resources are released after the sub-function is called. Pay attention to the details ~ Haha ~


Question:

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

Football is the most popular sport in the world (Americans insist on calling it "soccer", but we call it "football "). As we all know, Brazil has won the World Cup championship in the world (1958,1962, 1970 and 1994)

Cup titles (four of them: 1958,196 2, 1970 and 1994). As our national tournament have registrteams (and even regional tournaments have registrteams also) It's a very hard

A little old ....). Because we have many teams in the National Championship (even if there are many teams in the regional championship), it is very difficult to record these teams and their scores.

Task to keep track of standings with so many teams and games played!

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

Therefore, your task is simple: write a name that can receive the championship name, team name, and competition, and can output the points of the championship so far.

A team wins a game if it scores more goals than its opponent. obviusly, a team loses a game if it scores less goals. When both teams score the same number of goals, we

If a team scores more than the opponent, they will win the game. Obviously, if a team scores less, they will lose the game. If the two teams scored the same score,

Call it a tie. A team earns 3 points for each win, 1 point for each tie and 0 point for each loss.

The two teams are tied. Each time a team wins a game, it gets three points, one point for a single game, and one point for a single game.

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

The competition team will rank according to the following rules

  1. Most points earned. Maximum score
  2. Most wins. Maximum number of wins
  3. Most goal difference (I. e. goals scored-goals against) has the most
  4. Most goals scored. Maximum score
  5. Less games played. Minimum number of matches
  6. Lexicographic Order. 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

The input in the first line is an integer N (0 <n <1000). Next is the description of N tournaments. The first line of each game is the name of the championship.

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 <=

The championship name can contain any number of letters, numbers, and spaces. The name of a tournament can be as long as 100 characters at most. Next is a number t (1 <t <= 30)

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

Number of teams participating in the championship. In the next T line, each line has a team name. The team name may contain any ASCII code greater than 32, except '#' and '@'.

Character that have ASCII code greater than or equal to 32 (Space), before t for '#' and '@ 'characters, which will never appear in teamnames. no team name will have more than 30 characters.

No team name is more than thirty characters long.

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

The team name is followed by a non-negative integer g, representing the competition that has been completed in the championship.

Greater than 1000. Then, G lines will follow with the results of games played. They will follow this format:

G will not be greater than 1000. Then the next g row is the result of the competition. They will take the following form:

team_name_1#[email protected]#team_name_2
For instance, the following line:
Team A#[email protected]#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

This means there is a game between Team A and Team B, and team A scored 3 points and Team B scored 1 point. All scores are a non-negative integer not greater than 20.

There will not be in existent 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

You can ensure that the team that appears in each competition result has appeared in the previous team name stage and no team will compete with itself.

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

For each championship, you must first output a team name and then output the score based on the rules described above. It should be noted that when there is a draw, it is ordered by the dictionary, which is case-insensitive.

Shocould the tie-breaker be the lexographic order, it must be done case in senstive. The output format for each line is shown bellow:

The output format is as follows:

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

Sample Input

2World Cup 1998 - Group A4BrazilNorwayMoroccoScotland6Brazil#[email protected]#ScotlandNorway#[email protected]#MoroccoScotland#[email protected]#NorwayBrazil#[email protected]#MoroccoMorocco#[email protected]#ScotlandBrazil#[email protected]#NorwaySome strange tournament5Team ATeam BTeam CTeam DTeam E5Team A#[email protected]#Team BTeam A#[email protected]#Team CTeam A#[email protected]#Team DTeam E#[email protected]#Team CTeam E#[email protected]#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)

Source code:

# Include <stdio. h> # include <string. h> # include <ctype. h> typedef struct team {// all information of a team char name [35]; int point; int game_played; int win, loss, tie; int goal_differ, goal_scored, goal_against ;} team; team teams [30 + 5]; char tournament [100 + 5]; char result [100]; int N, t, q; void handle_str (char *, char *, char *, int *, int *); // The Void add_result (char *, char *, Int, INT) string that processes the competition results ); // Add the competition result to the corresponding node void sort (); void output_result (); Char * convert (char *); int main () {int I, j, k; char team_a [35], team_ B [35]; int score_a, score_ B; // freopen ("D: \ data.txt", "r", stdin); scanf ("% d \ n", & N); While (n --) {gets (tournament); scanf ("% d \ n", & T); for (I = 0; I <t; I ++) {// initialize the team information gets (teams [I]. name); teams [I]. point = teams [I]. game_played = 0; teams [I]. win = teams [I]. loss = teams [I]. tie = 0; teams [I]. goal_differ = teams [I]. goal_scored = teams [I]. goal_against = 0;} Scan F ("% d \ n", & Q); for (I = 0; I <q; I ++) {gets (result); handle_str (result, team_a, team_ B, & score_a, & score_ B); // process the competition result add_result (team_a, team_ B, score_a, score_ B); // Add the competition result} Sort (); output_result (); if (n) putchar ('\ n');} return 0;} void output_result () {// output result int I; printf ("% s \ n ", tournament); for (I = 0; I <t; I ++) {printf ("% d) % S % DP, % DG", I + 1, teams [I]. name, teams [I]. point, teams [I]. game_played); printf ("(% d-% d ), ", Teams [I]. win, teams [I]. tie, teams [I]. loss); printf ("% DGD (% d-% d) \ n", teams [I]. goal_differ, teams [I]. goal_scored, teams [I]. goal_against);} return;} void add_result (char * team_a, char * team_ B, int score_a, int score_ B) {// Add the match result int I; for (I = 0; I <t; I ++) if (strcmp (team_a, teams [I]. name) = 0) {teams [I]. game_played ++; teams [I]. goal_differ + = score_A-score_ B; teams [I]. goal_scored + = score_a; teams [I]. goal_against + = SCO Re_ B; If (score_a> score_ B) {teams [I]. point + = 3; teams [I]. win ++;} else if (score_a = score_ B) {teams [I]. point + = 1; teams [I]. tie ++;} else teams [I]. loss ++;} else if (strcmp (team_ B, teams [I]. name) = 0) {teams [I]. game_played ++; teams [I]. goal_differ + = score_B-score_A; teams [I]. goal_scored + = score_ B; teams [I]. goal_against + = score_a; If (score_ B> score_a) {teams [I]. point + = 3; teams [I]. win ++;} else if (score_a = score _ B) {teams [I]. point + = 1; teams [I]. tie ++;} else teams [I]. loss ++;} return;} void handle_str (char * result, char * team_a, char * team_ B, int * score_a, int * score_ B) {// processing result string int I, pos; int A = 0, B = 0; I = Pos = 0; while (result [POS]! = '#') Team_a [I ++] = Result [POS ++]; team_a [I] = '\ 0'; POS ++; while (isdigit (result [POS]) A = A * 10 + result [POS ++]-'0'; * score_a = A; POS ++; while (isdigit (result [POS]) B = B * 10 + result [POS ++]-'0'; * score_ B = B; POS ++; I = 0; while (result [POS]! = '\ 0') team_ B [I ++] = Result [POS ++]; team_ B [I] =' \ 0';} void sort () {int I, j; team temp; char team_a [35], team_ B [35]; for (I = 1; I <t; I ++) for (j = I; j> 0; J --) {// sort by the rules given by the question if (teams [J]. point <teams [J-1]. point) break; else if (teams [J]. point = teams [J-1]. point) {If (teams [J]. win <teams [J-1]. win) break; else if (teams [J]. win = teams [J-1]. win) {If (teams [J]. goal_differ <teams [J-1]. goal_differ) break; else if (teams [J]. goal _ Differ = teams [J-1]. goal_differ) {If (teams [J]. goal_scored <teams [J-1]. goal_scored) break; else if (teams [J]. goal_scored = teams [J-1]. goal_scored) {If (teams [J]. game_played> teams [J-1]. game_played) break; else if (teams [J]. game_played = teams [J-1]. game_played) {strcpy (team_a, teams [J]. name); strcpy (team_ B, teams [J-1]. name); If (strcmp (convert (team_a), convert (team_ B)> = 0) // note! Case-insensitive break ;}}}temp = teams [J]; teams [J] = teams [J-1]; teams [J-1] = temp ;}} char * convert (char * Team) {int I = 0; while (TEAM [I]) {If (isalpha (TEAM [I]) // The team name is not all the letters team [I] = tolower (TEAM [I]); I ++;} return team ;}











Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.