No older revisions available
No older revisions available
데블스 캠프 셋째날 스케쥴 워크 코드
~cpp #include <iostream> #include <ctime> using namespace std; const int Asize = 3; int main() { int board[Asize][Asize] = {0,}; srand(time(0)); int x = rand() % Asize; int y = rand() % Asize; cout << "시작 위치 : " << x << ", " << y << endl; board[x][y] = 1; char input; int tempx=x, tempy=y;//벽을 통과할때를 대비한 백업 while (input!='\n') { cin.get(input);//한자씩 입력받게 switch(input) { case '1' : tempx = x++; break; case '2' : tempx = x++, tempy = y++; break; case '3' : tempy = y++; break; case '4' : tempx = x--, tempy = y++; break; case '5' : tempx = x--; break; case '6' : tempx = x--, tempy = y--; break; case '7' : tempy = y--; break; case '8' : tempx = x++, tempy = y--; break; } if (x >= Asize || y >= Asize || x < 0 || y < 0)//벽 { x=tempx, y=tempy; continue; } board[x][y] += 1; } /////////////////////////////////////////////////////////////////////// board[x][y] -= 1;//마지막에 이상하게 하나가 더 더해져서 나온다...ㅡㅡ; /////////////////////////////////////////////////////////////////////// for (int j=0 ; j<Asize ; j++) { for (int k=0 ; k<Asize ; k++) cout << board[k][j] << "\t"; cout << endl; } cout << endl; return 0; }