Vues 229 Recommandés 0 Commentaire 0

#include <stdio.h>

int squ[10000][10000]={0};
int n;

int re(int x, int y, int c, int a);
void pr(void);
int main(void)
{
	scanf("%d", &n);

	re(1, 1, 1, 1);
	pr();

	return 0;
}
void pr(void)
{
	int i, j;
	for(i=1; i<=n; i++)
	{
		for(j=1; j<=n; j++)
			printf("%2d ", squ[i][j]);
		printf("\n");
	}
}
int re(int x, int y, int c, int a)
{
	if(c<=n*n && x>=1 && x<=n && y>=1 && y<=n && squ[x][y]==0)
	{
		if(a==1)
		{
			squ[x][y]=c;
			re(x, y+1, c+1, a);
		}
		if(a==2)
		{
			squ[x][y]=c;
			re(x+1, y, c+1, a);
		}
		if(a==3)
		{
			squ[x][y]=c;
			re(x, y-1, c+1, a);
		}
		if(a==4)
		{
			squ[x][y]=c;
			re(x-1, y, c+1, a);
		}
	}
	else
	{
		if(c>n*n)
			return 0;
		else if(x<1)
			re(x+1, y+1, c, (a%4)+1);
		else if(x>n)
			re(x-1, y-1, c, (a%4)+1);
		else if(y<1)
			re(x-1, y+1, c, (a%4)+1);
		else if(y>n)
			re(x+1, y-1, c, (a%4)+1);
		else if(squ[x][y]!=0)
		{
			if(a==1)
				re(x+1, y-1, c, (a%4)+1);
			else if(a==2)
				re(x-1, y-1, c, (a%4)+1);
			else if(a==3)
				re(x-1, y+1, c, (a%4)+1);
			else if(a==4)
				re(x+1, y+1, c, (a%4)+1);
		}
	}
}



List of Articles
No Titre Auteur Jour Vues
Notice 글쓰기는 하루 5개, 댓글은 10개만 가능합니다. 좋은아빠되기 2019.02.15 789
Notice 키보드 화살표값 출력 좋은아빠되기 2016.11.19 1551
Notice 원하는 좌표에 값 출력하기 좋은아빠되기 2016.11.19 2897
Notice Python(파이썬) 학습 자료 PDF 1 file 좋은아빠되기 2014.12.10 11325
Notice dev C++ 텍스트 색상변경 WinApi사용(textcolor 대용) 좋은아빠되기 2014.06.07 5222
Notice DEV-C++ 기본 코드 좋은아빠되기 2013.06.19 9050
Notice 무료 C++ 컴파일러(윈도우용) DEV-C++ 좋은아빠되기 2013.06.18 19490
Notice 이클립스 C++ 설치 파일들 좋은아빠되기 2013.06.18 38367
288 정올 대각선 지그재그 조정미 2017.11.18 774
287 정올 달팽이 삼각형 조정미 2017.11.18 611
286 정올 달팽이 사각형 조정미 2017.11.18 290
» 정올 달팽이 사각형(재귀) 조정미 2017.11.18 229
284 정올 실력키우기 1147번 주사위 쌓기 문제 2 갓초딩 2017.06.25 373
283 문자열2 형성평가2 갓초딩 2017.05.06 280
282 문자열2 형성평가1 갓초딩 2017.05.06 345
281 핵맨 선우 2017.04.01 278
280 배열2 형성평가 3 갓초딩 2017.04.01 241
279 겁나 쉬이이이이잉이이운 가위바위보 게임 갓초딩 2017.03.25 1984
278 주사위 굴리기 갓초딩 2017.03.25 1441
277 ㅇㅇㅇ 선우 2016.11.19 146
276 졸업문제 선우 2016.11.19 314
275 dd 승민 2016.11.19 143
274 dd 선우 2016.11.19 110
273 테두리(승민) 승민 2016.11.12 196
272 테두리(승민) 승민 2016.11.12 189
271 알파벳 배열2-1 승민 2016.10.29 218
Board Pagination Prev 1 ... 7 8 9 10 11 12 13 14 15 16 ... 26 Next
/ 26