출처 : 반크_세계무형유산 아리랑, 판소리
참고풀이]
//Dev-C++ 5.11로 작업함.
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int main(void) {
char board[10][10] = { {'#', '#', '#', '#', '#', '.', '.', '.', '.', '.' },
{'.', '.', '.', '.', '.', '#', '.', '.', '.', '.' },
{'#', '#', '#', '.', '#', '.', '.', '.', '.', '.' },
{'.', '.', '#', '.', '.', '#', '.', '.', '.', '.' },
{'.', '.', '#', '.', '.', '#', '.', '.', '.', '.' },
{'.', '.', '#', '.', '.', '#', '.', '.', '.', '.' },
{'.', '.', '.', '#', '.', '.', '#', '#', '.', '.' },
{'.', '.', '.', '.', '#', '.', '.', '.', '#', '#' },
{'.', '.', '.', '.', '.', '#', '.', '.', '.', '.' },
{'.', '.', '.', '.', '.', '#', '#', '#', '#', '#' } };
int xpos = 0, ypos = 1;
int x, y;
int ch, ch2;
board[ypos][xpos] = '@';
// 사용자로부터 위치를 받아서 보드에 표시한다.
while (1) {
system("cls");
printf("왼쪽이동: →, 오른쪽 이동: ←, 위쪽 이동: ↑, 아래쪽 이동: ↓\n");
for (y = 0; y < 10; y++) {
for (x = 0; x < 10; x++) printf("%c", board[y][x]);
printf("\n");
}
board[ypos][xpos] = '.';
ch = getch();
if (ch == 224) {
ch2 = getch();
if (ch2 == 75) xpos--; // ←
else if (ch2 == 80) ypos++; // ↑
else if (ch2 == 72) ypos--; // ↓
else if (ch2 == 77) xpos++; // →
}
if(ypos==10 || xpos==10) break;
if(board[ypos][xpos]=='#')
{
if (ch2 == 75) xpos++; // ←
else if (ch2 == 80) ypos--; // ↑
else if (ch2 == 72) ypos++; // ↓
else if (ch2 == 77) xpos--; // →
}
board[ypos][xpos] = '@';
}
printf("\n통과를 축하합니다!!!\n");
return 0;
}
참고풀이 결과]
대한민국의 아름다운 영토, 독도
댓글