BlueBook
p175ex5 - Magic Square
Determine if a table of numbers containing N rows and N columns is a magic square.
A N×N table of numbers (1 ≤ N ≤ 50) is a magic square if and only the sum of the numbers along any row or column is constant. The diagonals are not required to have the same sum.
Input
The first line of input contains an integer T (1 ≤ T ≤ 10), the number of test cases to follow.Each test case starts with an integer N (1 ≤ N ≤ 50), which is followed by N2 integers, each on its own line - the entries of the table, in reading order. This means that the first N integers represent the first row of the table, from left to right, the next N integers the second row likewise, and so on. There is a blank line between each pair of adjacent cases.
Output
For each test case, print "yes" if it is a magic square, and "no" if it is not.Sample Input
3 2 1 2 2 1 1 5 2 1 2 3 4
Sample Output
yes yes no
All Submissions
Best Solutions
Point Value: 4
Time Limit: 2.00s
Memory Limit: 16M
Added: Oct 23, 2008
Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3
Comments (Search)
It's quiet in here...