Map or Dictionary Data Structure
Find the Team who has the maximum points.
The problem can simply be solved by using maps or dictionary data structure.
According to the problem, there are team numbers from 1 to N
and each team play’s a match against all the remaining teams.
we can simply create a map or dictionary for counting the score of the teams and create another dictionary for counting the goals scored by the teams.
now initialize both dictionaries with keys from 1 to N. and giving each key a value of 0.
now take input and check if T1 is greater than t2 if that is the case then Score[T1] += 4 and if T2 is greater than T1 then Score[T2] += 4 else the match is a tie and both teams get one point.
we can calculate the goals in a similar fashion.n now we will check for the maximum point in the values of the dictionary score and store it in a separate variable maximum score now we we check that is there more than one team that has the score same as maximum score
if no then we will print the number of the team who has the maximum goal else we will check how many teams have the same score as the Maximum Score and store the teams number in an array now we will use the array to check that which team has scored the maximum goals. and print the number of the team who scored the maximum goal.
Author’s solution can be found here.