How to solve this problem ?

Revision en1, by Scofield11, 2019-04-21 20:51:16

There is a square 3x3 consisting of 9 natural numbers. The sum of every row, every column and both diagonals are mutually the same (row 1 has the same sum as row2, row3, column1, column2 etc.).

Some numbers were deleted from the square (deleted numbers are numbered as 0) and the task is to restore those numbers. It is guaranteed that the task is solvable and that there will never be more than 3 deleted numbers. All numbers are less than 20000.

Input:

5 10 3 
4 0 8                   
9 2 7

Output:

5 10 3
4 6 8
9 2 7

Input:

0 11 11
15 9 0
7 7 13

Output:

5 11 11
15 9 3
7 7 13

Input:

496 469 0
0 523 415
442 0 550

Output:

496 469 604
631 523 415
442 577 550

I have some ideas, and I've tried to do the task, but my way wouldn't work on all test cases.

Tags #c++, #matrix

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Scofield11 2019-04-21 20:51:16 935 Initial revision (published)