2016 Canadian Computing Competition

Problem J2: Magic Squares

Magic Squares are square arrays of numbers that have the interesting property that the numbers in each column, and in each row, all add up to the same total.

Given a 4 × 4 square of numbers, determine if it is a magic square.

Input Format

The input consists of four lines, each line having 4 space-separated integers.

Output Format

Output either magic if the input is a magic square, or not magic if the input is not a magic square.

Sample Input 1

16 3 2 13
5 10 11 8
9 6 7 12
4 15 14 1

Sample Output 1

magic

Explanation 1

Notice that each row adds up to 34, and each column also adds up to 34.

Sample Input 2

5 10 1 3
10 4 2 3
1 2 8 5
3 3 5 0

Sample Output 2

not magic

Explanation 2

Notice that the top row adds up to 19, but the rightmost column adds up to 11.

All Submissions
Best Solutions


Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Feb 22, 2016

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

Does it also require to check the diagonals

Magic Squares are square arrays of numbers that have the interesting property that the numbers in each column, and in each row, all add up to the same total.