#include <iostream>
using namespace std;
int x,y,a,b,stx,sty,snail[101][101],cycle,cy[1000]={0},cnt=1,r=1,xx[4]={-1,0,1,0},yy[4]={0,-1,0,1},c,q=0;
int main()
{
cin >> x;
cycle=x*2-2; // 0 0에서 역달팽이 시작점으로 가기위해 회전(꺽이는) 회수 계산
if(x%2==1)
stx=x-((x-1)/2)-1,sty=x-((x-1)/2)-1; // 달팽이 배열이 끝나는 지점 계산 수식
else
stx=x-x/2,sty=x/2; // 달팽이 배열이 끝나는 지점 계산 수식
snail[stx][sty]=r++; // 달팽이 배열의 끝점을 1로 지정함.
cycle--;
cy[cycle]=cnt;
for(int i=cycle; i>=0; i--)
{
if(i%2==0)
cnt++;
cy[i]=cnt;
}
cy[cycle]++;
stx+=xx[c],sty+=yy[c];
snail[stx][sty]=r++;
cy[cycle]--;
c++;
while(cy[cycle]>0)
{
stx+=xx[c],sty+=yy[c];
snail[stx][sty]=r++;
cy[cycle]--;
if(cy[cycle]==0)
{cycle--; c++; q++;}
if(c==4)
c=0;
if(r==x*x+1)
break;
}
for(int i=0; i<x; i++)
{
for(int j=0; j<x; j++)
{
cout << snail[i][j] << " ";
}
cout << endl;
}
}
꺾인 회수 계산한 이유는 역달팽이에서 달팽이 시작지점까지 가기 위해 구한거고,
끝점은 당연히 역달팽이 시작지점이니까 구한거임
ㄹ왜주?