This Forum is in read only mode now.

You are not logged in. Please login at www.codechef.com to post your questions!

×

UCL Editorial

PROBLEM LINK:

Practice
Contest

Author: Erfan alimohammadi
Tester & Editorialist: Hussain Kara Fallah

DIFFICULTY:

Cakewalk

PREREQUISITES:

None

PROBLEM:

Given the results of group stage matches in a champions league for one group. You need to determine the team on top of the group's table and the runner up. The group consists of 4 teams. Hence, 6 matches are held (between each pair).

In a single match, the team with more goals wins. When a team wins it gets 3 points, for a draw it gets 1 point and for losing it gets 0. Teams are sorted in descending order according to points, and in case of a tie according to goal difference (number of goals the team scored - the number of goals it conceded). It's guaranteed that the group's top team and the runner up are both unique.

EXPLANATION:

This a straight forward implementation problem.The best tool to solve it with is map (in C++) or any equivalent structure in any other programming language. If you don't know it, you must learn about it. In simple words, it creates a structure like a dictionary, which a field containing information about some word. Both the word and the info can be of any standard type or even (custom object but with some conditions I will not be mentioning).

So here we will have maps like:

map < string , int > points , goals;

The first map tells the number of points associated with each club name. For example points["barcelona"] indicates the number of points associated with the string "barcelona".

After we read the input, we fix the number of points associated with each team and the number of goals as well. After this, we can sort the 4 teams with any sorting algorithm (or even simple if cases) using the information in the maps.

In my C++ code, I wrote a custom comparator, that compares between two strings according to the data in the maps and then used it along with std::sort function. Please refer to my code for details.

AUTHOR'S AND TESTER'S SOLUTIONS:

AUTHOR's solution

TESTER's solution

This question is marked "community wiki".

asked 25 Mar, 22:27

deadwing97's gravatar image

3★deadwing97
1181234
accept rate: 0%

edited 26 Mar, 00:36

nehak_21's gravatar image

0★nehak_21 ♦♦
11

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×15,877
×1,695
×26
×8

question asked: 25 Mar, 22:27

question was seen: 178 times

last updated: 26 Mar, 00:36