N-level

xiaoxiao2021-03-05  28

#include

#define n 100

INT A [N] [N];

Void Magic (INT N)

{

INT I, J, T, U, V, X, Y;

/ Odd order (2K 1)

IF (N% 2! = 0)

{

Y = (n 1) / 2; x = y 1;

For (i = 1; i <= n * n; i )

{

a [x] [y] = i;

IF (i% n == 0) x = 2;

Else

{

X = 1;

Y = 1;

}

IF (x> n) x- = n;

IF (y> n) y- = n;

}

}

// Double orvened (4K)

IF (n% 4 == 0)

{

T = N * n;

For (i = 1; i <= n; i )

For (j = 1; j <= n; j )

IF ((i-j)% 4 == 0 || (i J-1)% 4 == 0)

{

a [i] [j] = t;

T- = 1;

}

Else

{

A [I] [j] = n * (i-1) j;

T- = 1;

}

}

// Single order (4K 2)

IF (n% 4! = 0 && n% 2 == 0)

{

u = n / 2; v = u * u; y = (u 1) / 2; x = y 1; t = y;

For (i = 1; i <= u * u; i )

{

a [x] [y] = i; a [x] [y u] = i 2 * v;

A [x u] [y] = i 3 * v; a [x u] [y u] = i v;

IF (i% u == 0)

X = 2;

Else

{

X = 1;

Y = 1;

}

IF (x> u) x- = u;

IF (y> u) y- = u;

}

For (i = 1; i <= u; i )

{

For (j = 1; j <= n; j )

IF (j <= t-1 || j> = n-t 3)

{

X = a [i] [j]; a [i] [j] = a [i u] [j]; a [i u] [j] = x;

}

X = a [t] [1]; a [t] [1] = a [t u] [1]; a [t u] [1] = x;

X = a [t] [t]; a [t] [t] = a [t u] [t]; a [t u] [t] = x;

}

}

}

void main ()

{

INT N, I, J;

Scanf ("% d", & n);

Magic (n);

For (i = 1; i <= n; i )

{

For (j = 1; j <= n; j )

Printf ("% 5D", A [i] [j]);

Printf ("/ n");

}

}

转载请注明原文地址:https://www.9cbs.com/read-33847.html

New Post(0)