{{{~cpp #include #include using namespace std; void main() { ifstream fin("input.txt"); ofstream fout("output.txt"); int m, n; fin >> m >> n; int i, j, k; int **array = new int*[m]; for (i = 0; i < m; i++) array[i] = new int[n]; for (i = 0; i < m; i++) for (j = 0; j < n; j++) array[i][j] = 0; int x, y; fin >> y >> x; array[y][x] = 1; while (fin.get() != '\n') ; char temp; char dir_arr[80]; int dirsu = 0; while ((temp = fin.get()) && temp != '\n') //방향있는 한 줄 입력받음 dir_arr[dirsu++] = temp; int cx = x, cy = y; bool flag; int cnt = 0; for (k = 0; k < dirsu; k++) { switch (dir_arr[k]) { case '7': cx--; cy--; break; case '0': cy--; break; case '1': cx++; cy--; break; case '6': cx--; break; case '2': cx++; break; case '5': cx--; cy++; break; case '4': cy++; break; case '3': cx++; cy++; break; } if (cx == -1) cx = n - 1; else if (cx == n) cx = 0; if (cy == -1) cy = m - 1; else if (cy == m) cy = 0; array[cy][cx]++; cnt++; flag = true; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) if (array[i][j] == 0) { flag = false; break; } if (flag == false) break; } if (flag == false) continue; else break; } fout << cnt << endl; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) fout << array[i][j] << " "; fout << endl; } } }}} ---- [RandomWalk2] [데블스캠프2003/셋째날]