#include <stdio.h>
#define DEFAULT 0
#define NORTH 1
#define SOUTH 2
#define EAST 3
#define WEST 4
#define MAX 10
int ladder[MAX + 1][MAX + 1];
int curX, curY;
int startX, startY;
int endY;
int main(void)
{
int test_case;
int T;
freopen("input.txt", "r", stdin);
setbuf(stdout, NULL);
for (test_case = 1; test_case <= 10; ++test_case)
{
scanf("%d", &T);
for (int i = 0; i < MAX; i++)
{
for (int j = 0; j < MAX; j++)
{
scanf("%1d", &ladder[i][j]);
}
}
curX = 0;
curY = 0;
int from = DEFAULT;
int move = 0;
int move_min = 10000;
int min_Y = 0;
for (int j = 0; j < MAX; j++)
{
if (ladder[0][j] == 1)
{
int while_break = 1;
startY = j;
curX = 0;
curY = j;
while (while_break)
{
if (curX == MAX-1)
{
//작은위치와 값기록
if (move_min > move)
{
move_min = move;
min_Y = startY;
}
while_break = 0;
move = 0;
continue;
}
if (from != EAST && ladder[curX][curY - 1] == 1)
{
curY--;
from = WEST;
move++;
continue;
}
else if (from != WEST && ladder[curX][curY + 1] == 1)
{
curY++;
from = EAST;
move++;
continue;
}
else if (from != SOUTH && ladder[curX + 1][curY] == 1)
{
curX++;
from = NORTH;
continue;
}
}
}
}
printf("#%d %d\n", test_case, min_Y);
}//
return 0;
}
댓글