������ ������ Random��� ���������... Scheduled��� ��깝겠���.
~cpp //RandomWalk2 //Random Walk #include<iostream.h> int main() { //������������==================================== char way[20];//������������ ������(8������: 0~7) int input_y, input_x;//��������� ���개��� int start_y, start_x;//������������ ������ int journey=0; int y, x;//��������� ������ ������ int i, j;//for��� ��������� ��� ��������� ������ int count=0;//��� ��������� ��� int first_go=0; for(i=0;i<20;i++) way[i]='\0'; //x, y ��������������� ���������고 ������������, ���기���=== cout<<"\n x������ ������ ���������������: "; cin>>input_x; cout<<"\n y������ ������ ���������������: "; cin>>input_y; int **base=new int *[input_y]; for(i=0;i<input_x;i++) base[i]=new int [input_x]; for(i=0;i<input_y;i++){ for(j=0;j<input_x;j++) base[i][j]=0;} //��������� ������, ������=========================== cout<<"\n ������������ x��������� ���������������: "; cin>>start_x; cout<<"\n ������������ y��������� ���������������: "; cin>>start_y; y=start_y; x=start_x; base[y][x]=1;//������������ ������ ��� ��� ������������ 1 first_go++; //������ ������=================================== cout<<"갈 ������ ������: "; cin>>way; do{ //������ ������=================================== switch(way[journey]){ case '0'://��� if(y==0) y=input_y-1; else y--; if(base[y][x]==0) first_go++; base[y][x]++; count++; journey++; break; case '1'://������ if(y==0) y=input_y-1; else if(x==input_x-1) x=0; else if(y==0 && x==input_x-1){ x=0; y=input_y-1;} else{ y--; x++;} if(base[y][x]==0) first_go++; base[y][x]++; count++; journey++; break; case '2'://��� if(x==input_x-1) x=0; else x++; if(base[y][x]==0) first_go++; base[y][x]++; count++; journey++; break; case '3'://������ if(y==input_y-1) y=0; else if(x==input_x-1) x=0; else if(y==input_y-1 && x==input_x-1){ y=0; x=0;} else{ y++; x++;} if(base[y][x]==0) first_go++; base[y][x]++; count++; journey++; break; case '4'://��� if(y==input_y-1) y=0; else y++; if(base[y][x]==0) first_go++; base[y][x]++; count++; journey++; break; case '5'://������ if(y==input_y-1) y=0; else if(x==0) x=input_x-1; else if(y==input_y-1 && x==0){ y=0; x=input_x-1;} else{ y++; x--;} if(base[y][x]==0) first_go++; base[y][x]++; count++; journey++; break; case '6'://��� if(x==0) x=input_x-1; else x--; if(base[y][x]==0) first_go++; base[y][x]++; count++; journey++; break; case '7'://������ if(y==0) y=input_y-1; else if(x==0) x=input_x-1; else if(y==0 && x==0){ y=input_y-1; x=input_x-1;} else{ y--; x--; } if(base[y][x]==0) first_go++; base[y][x]++; count++; journey++; break; default: break; } }while(way[journey]!='\0'); cout<<"\n��� ������ ��������� "<<count<<"���\n"; for(i=0;i<input_y;i++){ for(j=0;j<input_x;j++) cout<<base[i][j]<<" "; cout<<"\n";} //��������������� �� ������ for(i=0;i<input_x;i++) delete[] base[i]; delete [] base; return 0; }
���������: Yggdrasil