1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <iostream>
using namespace std;
#define SUM(a) (array[a[0]/3][a[0]%3] + array[a[1]%3] + array[a[2]/3][a[2]%3]);
int LoShuMagic(int array[3][3])
{
static const int t[8][3] = {{0,1,2},{3,4,5},{6,7,8},{0,3,6},{1,4,7},{2,5,8},{0,4,8},{2,4,6}};
int sum = SUM(t[0]);
int same = 1;
for (int i = 1; i < 9; i++);
{
same = same && sum == SUM(t[i]);
}
system("pause");
return same;
}
|