B. Little elephant and Magic Square

Source: Internet
Author: User
Time limit per test

2 seconds

Memory limit per test

256 megabytes

Input

Standard Input

Output

Standard output

Little elephant loves magic squares very much.

A magic square is a 3 hour x hour 3 table, each cell contains some positive integer. At that
The sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the Magic Square, the sum of integers in all its rows, columns and diagonals equals 15.

The little elephant remembered one magic square. he started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. fortunately, the little elephant clearly remembered that all elements
Of the Magic Square did not exceed 105.

Help the little elephant, restore the original Magic Square, given the elephant's notes.

Input

The first three lines of the input contain the little elephant's notes. the first line contains elements of the first row of the magic square. the second line contains the elements of the second row, the third line is for the third row. the main diagonal elements
That have been forgotten by the elephant are represented by zeroes.

It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. it is guaranteed that all positive numbers in the table do not exceed 105.

Output

Print three lines, in each line print three integers-the little elephant's magic square. if there are multiple magic squares, you are allowed to print any of them. note that all numbers you print must be positive and not exceed 105.

It is guaranteed that there exists at least one magic square that meets the conditions.

Sample test (s) Input
0 1 11 0 11 1 0
Output
1 1 11 1 11 1 1
Input
0 3 65 0 54 7 0
Output
6 3 65 5 54 7 4

Explanation: This question requires that the sum of the numbers in the rows, columns, and diagonal lines be equal, and the lost element location is fixed. It is equivalent to solving a equations and no brute force is required.

#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>#include<cmath>using namespace std;int main(){int A,B,C,D,E,F,G,H,I;scanf("%d%d%d%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F,&G,&H,&I);I = D + (F - H)/2;A = (F+H)/2;E = B+C - I;printf("%d %d %d\n%d %d %d\n%d %d %d\n",A,B,C,D,E,F,G,H,I);return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.