U E D R , A S I H C RSS

Random Walk/이진훈

---
~cpp 
#include <iostream>
#include <ctime>
using namespace std;

const int Arsize = 3;
int pan[3][3] =	{
				{0,0,0},
				{0,0,0},
				{0,0,0}
				};

int count = 1;
int count00 = 0;
int count01 = 0;
int count02 = 0;
int count10 = 0;
int count11 = 0;
int count12 = 0;
int count20 = 0;
int count21 = 0;
int count22 = 0;

int countz();


void main()
{
	srand(time(0));
	int x = rand()%3;
	int y = rand()%3;
	int a = 0 , b = 0;
	int z = countz();
	while(z)
	{
	x = x+a;
	y = y+b;
	pan[x][y] = 1;
		do
		{
		a = rand()%3 - 1;
		b = rand()%3 - 1;
			if (a == 0 && b == 0)
				continue;
			else if ((x+a >= 0 && x+a < 3) && (y+b >= 0 && y+b < 3))
			{
				if (x+a == 0 && y+b == 0)
					count00++;
				else if (x+a == 0 && y+b == 1)
					count01++;
				else if (x+a == 0 && y+b == 2)
					count02++;
				else if (x+a == 1 && y+b == 0)
					count10++;
				else if (x+a == 1 && y+b == 1)
					count11++;
				else if (x+a == 1 && y+b == 2)
					count12++;
				else if (x+a == 2 && y+b == 0)
					count20++;
				else if (x+a == 2 && y+b == 1)
					count21++;
				else if (x+a == 2 && y+b == 2)
					count22++;
				break;
			}
		}while(true);
	count++;
	z = countz();
	}
	for (int i = 0;i<3;i++)//출력부..
	{
		for (int k = 0;k<3;k++)
			cout << pan[i][k];
		cout << endl;
	}
	cout << count00 << " " << count01 << " " << count02 << endl;
	cout << count10 << " " << count11 << " " << count12 << endl;
	cout << count20 << " " << count21 << " " << count22 << endl;
}

int countz()//빈칸없나 체크하는 함수.
{
	int k = 0;
	for (int i = 0;i<3;i++)
		for(int j = 0;j<3;j++)
		{
			if (pan[i][j] == 0)
				k++;		
		}
		return k;
}
---
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:27:51
Processing time 0.0074 sec