2 1 료 ¶
~cpp #include <iostream> #include <ctime> #include <iomanip> using namespace std; void main(){ srand(time(0)); //바벌를 8방 동 배 int imove[] = {-1,0,1,1,1,0,-1,-1}; int jmove[] = {1,1,1,0,-1,-1,-1,0}; // 방 int Xroom; int Yroom; // 바벌 int ibug; int jbug; int count = 0; // 동 를 integer bool existZero = false; // 바벌 모 돌녔는 bool int i,j; // 바벌 돌 방 do{ cout << " 를 (2 < X <= 40) :"; cin >> Xroom; cout << " 를 (2 <= Y < 20) :"; cin >> Yroom; if (Xroom > 2 && Xroom < 41 && Yroom > 1 && Yroom < 21) break; cout << ", 범를 벗났. ." << endl; }while(true); // 2동배 만는 int **room; room = new int*[Xroom]; for (i=0; i<Xroom; i++) room[i] = new int[Yroom]; // 동배 for (i=0;i<Xroom;i++) for(j=0;j<Yroom;j++) room[i][j] =0; // 바벌를 는 do ~ while 문 do{ cout << "바벌 X를 :"; cin >> ibug; cout << "바벌 Y를 :"; cin >> jbug; if (ibug >= 0 && ibug < Xroom && jbug >= 0 && jbug < Yroom) break; cout << "바벌 방 범를 벗났. ." << endl; }while(true); room[ibug][jbug] = 1; // 바벌 // 바벌를 동 모 동면 료는 while문 while(count<50000 && existZero == false){ existZero = true; for(i=0;i<Xroom;i++){ for(j=0;j<Yroom;j++){ if(room[i][j] == 0) existZero = false; } } int random = rand()%8; // 0~7 random 란 integer 대 // 바벌 범를 벗 는 if (ibug + imove[random] <0 || ibug + imove[random] > Xroom-1 || jbug + jmove[random] <0 || jbug + jmove[random] > Yroom-1) continue; // 바벌를 동 를 는 else{ room[ibug+imove[random]][jbug+jmove[random]]++; ibug = ibug + imove[random]; jbug = jbug + jmove[random]; count++; } } //동 cout << " 방 동 : \n\n"; for(i=0;i<Xroom;i++){ for(j=0;j<Yroom;j++) cout << setw(3) << room[i][j]; cout << endl; } // 동 cout << "\n 동 :" << count << endl; //메모리 for (i=0; i<Xroom;i++) delete[] room[i]; delete [] room; }
¶
딩 |
대략2 |
리는데 는데..
2동배 본
만 C++ 딩보는듯... 미
른 낮 면 더 방듯.. 3 몽롱..