Completing a League Table
InterviewTime limit1sMemory limit128 MB
Fill in missing values (marked ?) in each football league row using matches=wins+draws+losses and points=3*wins+draws, with a unique solution guaranteed.
- Level
Easy3 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
A football league table stores five values for each team. In order, they are the number of matches, wins, draws, losses, and points. A win gives 3 points, a draw gives 1 point, and a loss gives no points.
Some cells of a table have been erased and are written as ?. For each team, only the following relationships matter.
- matches = wins + draws + losses
- points = 3 × wins + draws
Rows are independent of one another. You do not need to decide whether the table could come from a real schedule; complete each row separately.
Each team has played at most 100 matches. The input is guaranteed to have exactly one way to fill every ?.
Input
The first line contains the number of teams N. (1 ≤ N ≤ 1000)
Each of the next N lines contains five pieces of information for one team, separated by spaces. Their order is matches wins draws losses points. Each item is either an integer or ?, where ? means that the value is unknown.
Output
Print the completed table in the same order as the input.
Each line must contain matches wins draws losses points, separated by spaces.