RandomWalk.. ---- {{{~cpp #include #include using namespace std; /* { srand(time(0)); // rand()의 시드값을 설정합니다. // 하지 않으면 실행할때마다 같은값을 만듭니다. -_-;; int x = rand(); // rand()함수는 랜덤한 숫자를 리턴하는 함수입니다. // 리턴하는 숫자의 범위는 0 ~ 무지무지 큰 수 입니다. int x1 = rand() % 10; // % 10 연산을 하면 x1 에는 10의 나머지가 될 수 있는 // 0 ~ 9 까지의 숫자가 랜덤하게 들어갑니다. int x2 = rand() % 9 + 1; // % 9를 하면 0~8까지의 숫자가 들어갈 수 있고 // 거기에 1을 더하면 1~9 까지의 숫자가 됩니다. return 0; } */ void main() { srand(time(0)); int arr[5][5] = {{0,},}; int x = rand() % 5; int y = rand() % 5; arr[x][y] = 1; while( ) { } switch(num) { case 1 : x=x-1; y=y+1; break; case 2 : x=x; y=y+1; break; case 3 : x=x+1; y=y+1; break; case 4 : x=x-1; y=y; break; case 5 : x=x+1; y=y; break; case 6 : x=x-1; y=y-1; break; case 7 : x=x; y=y-1; break; case 8 : x=x+1; y=y-1; break; } arr[x][y] += 1; /* do { for(int i=0; i<5; i++) { for(int j=0; j<5; j++) { } } } */ int i,j; for(i=0; i<5; i++) { for(j=0; j<5; j++) { if (arr[i][j] == 0) //함수를 부르면 되겠다... } } for(i=0; i<5; i++) { for(j=0; j<5; j++) { } } while (arr[i][j] !=0) //루프를 돌려서 표현을 하고... arr[i][j] != 0 //참이면 값을 출력한다... cout << arr[i][j] }while( /* if(x>0 && x<4 && y>0 && y<4) { int i = rand() % 3 -1; int j = rand() % 3 -1; arr[x-i][y-j] } else if (x>0 && x<4 && y==0) { int k = rand() % 3 -1; int l = rand() ; arr[x-i] */ // 배열에 있는 숫자를 출력할 수 있다... for(int i=0; i<5; i++) { for(int j=0; j<5; j++) { cout << arr[i][j] ; } cout << endl; } } }}} ---- [RandomWalk] [손동일]