λ°λΈμ€ μΊ ν μ
μ§Έλ μ€μΌμ₯΄ μν¬ μ½λ
~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;
}
μλ €μ§ μ€λ₯ : μμ μμΉκ° 0,0 μ΄κ³ 1117661μ μ
λ ₯νλ©΄ 2,0 μ§μ μ μ«μκ° 2κ° λμ¨λ€..γ
‘γ
‘; μμ΄μ§??










