&emspinclude "iostream"
using namespace std;
&emspdefine RIGHT 1
&emspdefine DOWN 2
&emspdefine LEFT 3
&emspdefine UP 4
int judge(int step, int walk, int flag)
{
if( walk< step )return flag;
switch(flag)
{
case RIGHT:
return DOWN;
case DOWN:
return LEFT;
case LEFT:
return UP;
case UP:
return RIGHT;
}
}
void matrix(int N)
{
int length = N * N;
int *p = new int[length];
int flag = RIGHT;
int step = N;
int count = 0;
int walk = -1;
for(int i = 0 ; i< length ; i )
{
walk = 1;
int n
ewflag = judge(step , walk , flag);
if(flag != newflag)
{
count = 1;
flag = newflag;
walk = 0;
if( (count 1) % 2 == 0 )
{
step -= 1;
}
}
switch(flag)
{
right
case RIGHT:
if(i == 0)
p[i] = 0;
else
p[i] = p[i - 1] 1;
break;
down
case DOWN:
p[i] = p[i - 1] N;
break;
left
case LEFT:
p[i] = p[i - 1] - 1;
break;
up
case UP:
p[i] = p[i - 1] -N;
}
}
int *tmp = new int[length];
for(int j = 0; j< length; j )
{
tmp[p[j]] = j 1;
}
for(j = 0; j< length; j )
{
cout