问题2305--Magic Squares

2305: Magic Squares

[命题人 : ]
时间限制 : 1.000 sec  内存限制 : 64 MB

题目描述

A magic square is a square matrix of numbers. where the sums of the numbers in each row, each column, and both main diagonals are the same. For instance, the following square is magic with 15 as the common sum: 8 3 4 1 5 9 6 7 2 The input file contains several square matrices. You are to find out whether they are magic.

输入

Each test case in your input file starts with a line containing a single integer n (1 <= n <= 10 ): the number of rows (and columns) in the square matrix. This is followed by n lines each containing n blank-separated integers. A test case starting with n = 0 terminates the input. It should not be processed.

输出

For each square, output the line "Square #k:", where k is the number of the square. Then output either "This square is magic." or "This square is not magic", depending whether the square matrix is magic or not. Output one blank line after each test case.

样例输入 Copy

3
8 3 4
1 5 9
6 7 2
4
1 2 3 4
2 1 4 3
4 3 2 1
3 4 1 2
0

样例输出 Copy

Square 1
This square is magic.

Square 2
This square is not magic.