HDU-1225 Football Score

Source: Internet
Author: User

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1225

A super simple question, because I forgot to write the return, Wa for a long time. Please be careful.

Learning: But how to find the string and return the subscript

Football Score

Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 2739 accepted submission (s): 785


Problem descriptionfootball is one of the greatest games in the world. lots of people like to play football. after one season of matches, the header has to calculate the last scores of every team. he is too lazy that he doesn't want to calculate, so he asks you to write a program for him to solve the problem.

Here are the rules:
1 Every team has to match with all the other teams.
2 every two teams have to match for two times, one at home and one away.
3 In one match, the winner will get 3 points, the loser will get 0 point. If it is draw, both of them will get 1 point.

 

Inputthe input consists of your test cases. in each case, there will be a number N in the first line which means the number of teams. followed by N * (N-1) lines. each line stands for a match between two teams. the format is: "team1 vs Team2 P: Q", P stands for the bils that team1 has kicked in and Q stands for the bils that Team2 has kicked in. p and q are not greater than 9.

Process to the end of file.

 

Outputfor each test case, output the teams and their scores in descending order. one line a team, the format is: "teamx scores ". if two teams get the same score, the one with high net goals will be ahead, which net goal means the difference between the total ballthat the team kicked in and the total ballthat the team lost. IE: If one team kicked in 30 bils and lost 40 bils, then the net goal is 30-40 =-10. if two teams have the same score and the same net goal, the one whose kicked in bils is bigger will be ahead. if two teams have the same score and the same net goal and the same kicked in bils, they will be outputed in alphabetic order.

Output a blank line after each test case.

 

Sample input3 Manchester vs Portsmouth Liverpool vs Manchester 1: 1 Liverpool vs Portsmouth 0: 0 Portsmouth vs Manchester 1: 1 Manchester VS Liverpool 2:1 Liverpool vs Portsmouth

 

Sample outputmanchester 8 Portsmouth 5 Liverpool 2
# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> using namespace STD; int t; struct node {char name [150]; int kick; int net; int score;} A [1, 50000]; bool CMP (Node B, node c) {If (B. score = C. score) {If (B .net = c.net) {If (B. kick = C. kick) return strcmp (B. name, C. name) <0? 1:0; else return B. kick> C. kick;} else return B .net> c.net;} else return B. score> C. score;} int find (char ss []) // finds the string and returns the subscript {int I; If (t =-1) {strcpy (A [0]. name, SS); t = 0; return t;} for (I = 0; I <= T; I ++) if (strcmp (A [I]. name, SS) = 0) return I; t ++; strcpy (A [T]. name, SS); Return t;} int main () {int N, I, X, Y, p, q; char str1 [100], str2 [40], str3 [100]; while (~ Scanf ("% d", & N) {T =-1; memset (A, 0, sizeof (a); for (I = 1; I <= N * (n-1); I ++) {scanf ("% s", str1); X = find (str1); scanf ("% s ", str2); scanf ("% s", str3); y = find (str3); scanf ("% d: % d", & P, & Q ); A [X]. kick + = P; A [X]. net + = p-Q; A [Y]. kick + = Q; A [Y]. net + = Q-P; If (P> q) A [X]. score + = 3; else if (q> P) A [Y]. score + = 3; else {A [X]. score + = 1; A [Y]. score + = 1 ;}} sort (A, A + T + 1, CMP); for (I = 0; I <= T; I ++) {printf ("% S % d \ n", a [I]. name, a [I]. score);} printf ("\ n");} return 0 ;}

 

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.