10415 - Problem2   

Description

Consider a 7x14 map, where each position on the map has a value of 0, 1, 2, or 3 indicating the moving direction for that position. The representation: 0 for up, 1 for right, 2 for down, and 3 for left..
For example:
1 2 3 0 1 2 3 1 2 3 0 1 2 3
0 1 2 3 3 2 1 1 2 3 0 1 2 3
1 1 2 2 3 3 0 1 2 3 0 1 2 3
2 2 3 3 0 0 1 1 2 3 0 1 2 3
1 1 2 2 3 3 0 1 2 3 0 1 2 3
2 2 3 3 0 0 1 1 2 3 0 1 2 3
2 2 3 3 0 0 1 1 2 3 0 1 2 3

Start from the upper-left corner, follow the moving direction denoted by the value at each position. Stop when you reach the boundary of the map or when you reach a position that has been visited. Print the total number of visited positions, which should be 12 for the above example.

Complete the program by replacing ??? with correct code:

#include 
#define ROWS 7
#define COLS 14
int map[ROWS+2][COLS+2];
int visited[ROWS+2][COLS+2];
int main(void)
{
    int i, j, direction, num;
    int d_row[] = { ??? , ??? , ??? , ??? };
    int d_col[] = { ??? , ??? , ??? , ??? };

    for (i=0; i
  

Input

The 7x14 map.

Output

Print the total number of visited positions.
Newline character at the end.

Sample Input  Download

Sample Output  Download

Tags




Discuss