Please note that these challenges are not self-made, please don't cheat by searching for it on google and getting a solution from elsewhere.
World Cup is going on! One of the most fascinating parts of it is the group stage that has recently ended. A lot of great teams face each other to reach the playoff stage. In the group stage, each pair of teams plays exactly one game and each team receives 3 points for a win, 1 point for a draw and 0 points for a loss.
You fell asleep. What a shame. While you were sleeping, your team has played a lot of games! Now you know how many matches your team has played, how many goals it has scored and how many has missed. Now you need to find out the maximum amount of points your team can have.
Please keep the meat of your solution inside one function with the following definition:
int maxPoints(int matches, int goalsFor, int goalsAgainst)
Examples you can test your code against are below. Please provide these inside your main function as maxPoints(matches,goalsFor,goalsAgainst) == solution. I will test your code with several solutions that are not listed here to ensure it functions according to the specifications.
| matches |
goalsFor |
goalsAgainst |
Expected Output |
| 2 |
1 |
2 |
3 |
| 2 |
3 |
2 |
4 |
| 3 |
3 |
5 |
6 |
| 2 |
3 |
3 |
3 |
| 1 |
2 |
4 |
0 |
| 2 |
1 |
4 |
3 |
| 1 |
4 |
1 |
3 |
| 1 |
5 |
5 |
1 |
| 2 |
2 |
2 |
3 |
| 3 |
2 |
1 |
6 |
Please follow these steps when submitting solutions:
Copy or create your solution over at
https://www.ideone.com/.
Make sure it's set to secret! Else your solutions can show up to everyone.
Next, copy the URL you get from here over to
https://***********/url/make, set a password of your chosing and reply to this topic with ONLY the short URL, and then send me a private message with the password to your solution.