_ | 覦覈襦 | 豕蠏手 | 殊螳 | 譯殊碁
FrontPage › 讌襤一鮎蠍
/*讌襤磯悪*/
/*
1. 讌襤磯悪 蠍磯ゼ 
2. 讌襤磯 '*' 襦 螻, 讌襤郁  蟆 '.'朱 .
3. レ 覃 讌襤郁  螻褐 豢ロ.
4. 讌襤磯悪 0, 0企 譬襭.
5. C++豐覲伎 殊螳 襦蠏碁 讌蟆企 ..覲願 讌 蟆 る 讌 譯朱 譬蟆..
*/


/* 蟆郁骸

讌襤磯悪 : X, Y豢 ロ.
X豢: 4
Y豢: 4
讌襤磯ゼ ロ. (讌襤: *, 讌襤郁 蟆: .)
*...
....
.*..
....

Field #1
* 1 0 0
2 2 1 0
1 * 1 0
1 1 1 0

讌襤磯悪 : X, Y豢 ロ.
X豢: 3
Y豢: 3
讌襤磯ゼ ロ. (讌襤: *, 讌襤郁 蟆: .)
***
*.*
***

Field #2
* * *
* 8 *
* * *

讌襤磯悪 : X, Y豢 ロ.
X豢: 0
Y豢: 0
覓危る 襯企 譬襭.

*/

#include "stdafx.h"
#include <iostream>
#include <string>
#define Y_SIZE 100

using namespace std;


//螳  讌襤 
class CCreateMine	
{
private:
	char* pX;

public:
	CCreateMine(int x);
	~CCreateMine();
	void InputMineX(int x);
	char OutputMineX(int x);
};

//讌襤 
CCreateMine::CCreateMine(int x)
{
	pX = new char[x];
}

//覃語
CCreateMine::~CCreateMine()
{
	delete pX;
}

//讌襤一
void CCreateMine::InputMineX(int x)
{
	for(int i = 0; i < x; i++)
	{
		cin >> pX[i];
	}
}

//讌襤一
char CCreateMine::OutputMineX(int x)
{
	return pX[x];
}

//螳 襦磯ゼ ロ 企
class CRowStorage
{
private:
	int x;
	int y;
	CCreateMine* pArray[Y_SIZE];	//Y_SIZE 100
public:
	CRowStorage();
	void InputXY();
	void InputMineY();
	void OutputMineY();
	int returnX();
	int returnY();
};

CRowStorage::CRowStorage()
{
	x = 0;
	y = 0;
}

//讌襤磯悪 X, Y 
void CRowStorage::InputXY()
{
	cout << "讌襤磯悪 : X, Y豢 ロ." << endl;
	cout << "X豢: ";
	cin >> x;
	cout << "Y豢: ";
	cin >> y;

	if(x > 0 && y > 0)
		cout << "讌襤磯ゼ ロ. (讌襤: *, 讌襤郁 蟆: .)" << endl;
	else
		return;
}

//螳 襦磯襦 讌襤磯ゼ ル.
void CRowStorage::InputMineY()
{
	if(x > 0 && y > 0 && y <= Y_SIZE)	//Y_SIZE 100
	{
		for(int i = 0; i < y; i++)
		{
			pArray[i] = new CCreateMine(x);
			pArray[i]->InputMineX(y);
		}
		cout << endl;
		
	}
	else
	{
		cout << "讌襤磯悪 X, Y 覿 ロ伎 ." << endl;
		CRowStorage::InputXY();
	}
}


//讌襤一
//讌襤一企 * 覃 ,  -> [i+1], 譬,  -> [i-1]
void CRowStorage::OutputMineY()
{
	int num = 0;

	if(x > 1 && y > 1 && y <= Y_SIZE)	//Y_SIZE 100
	{
		for(int i = 0; i < y; i++)
		{
			for(int j = 0; j < x; j++)
			{
				char ch = pArray[i]->OutputMineX(j);

				if(ch != '*')	//讌襤郁 覃 譯朱 讌襤郁 讌 
				{
					for(int i2 = i - 1; i2 <= i + 1; i2++)
					{
						for(int j2 = j - 1; j2 <= j + 1; j2++)
						{
							if(i2 >= 0 && i2 < y)
							{
								if(j2 >= 0 && j2 < x)
								{
									if(pArray[i2]->OutputMineX(j2) == '*')
										num++;
								}
							}
						}
					}
					cout << num << " ";
				}
				else			//讌襤一企
				{
					cout << "*" << " ";
				}

				num = 0;

				if(j == x - 1)
						cout << endl;
			}
		}
	}
	else
	{
		cout << "讌襤磯悪 X, Y襯 (x, y 覈 1 伎)伎 ." << endl;
		CRowStorage::InputXY();
	}
}

int CRowStorage::returnX()
{
	return x;
}

int CRowStorage::returnY()
{
	return y;
}

int _tmain(int argc, _TCHAR* argv[])
{
	int i = 1;
	CRowStorage* rs = new CRowStorage();

	do
	{
		rs->InputXY();
		
		if(rs->returnX() > 0 && rs->returnY() > 0)
		{
			rs->InputMineY();
			cout << "Field #" << i << endl;
			rs->OutputMineY();
			cout << endl;
		}
		i++;
		
	}while(rs->returnX() > 0 || rs->returnY() > 0);
	
	delete rs;

	cout << "覓危る 襯企 譬襭.";
	cin.ignore(i);
	cout << endl;

	return 0;
}







蠍 蠍郁鍵..
企: : るジ讓曙 襦螻豺 企Ν 譯殊語. 襦螻豺
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2018-04-13 23:12:53

瑚 覈旧朱 る 蠏碁 觜讌 蟆企. 讌襷 蠏碁ゼ 覩碁 螳ロ 覈旧朱 覦朱慨 蠏碁覃 蠏碁 襷襦 蠏碁 蟆企. (蟯危)