U E D R , A S I H C RSS

잔디밭/권순의

소스

#include <iostream>
#include <malloc.h>

using namespace std;

int main()
{
	int getRow = 0;
	int getCol = 0;
	int greatestNum = 0;
	int currentRow = 0;
	int currentCol = 0;
	int **lawn;
	int temp = 0;

	cin >> getRow >> getCol;

	while((getRow < 3) || (getCol < 3))
		cin >> getRow >> getCol;

	lawn = (int**)malloc(sizeof(int) * getRow);

	for(int i = 0; i < getRow; i++)
		*(lawn + i) = (int*)malloc(sizeof(int) * getCol);

	for(int i = 0; i < getRow; i++)
	{
		for(int j = 0; j < getCol; j++)
			cin >> lawn[i][j];
	}

	for(int i = 0; i < (getRow - 2);i++)
	{
		for(int j = 0; j < (getCol - 2); j++)
		{
			temp = lawn[i][j] + lawn[i][j + 1] + lawn[i][j + 2] + 
				lawn[i + 1][j] + lawn[i + 1][j + 1] + lawn[i + 1][j + 2] + 
				lawn[i + 2][j] + lawn[i + 2][j + 1] + lawn[i + 2][j + 2];

			if(temp > greatestNum)
			{
				greatestNum = temp;
				currentRow = i + 1;
				currentCol = j + 1;
			}
		}
	}

	cout << greatestNum << endl << currentRow << " " << currentCol << endl;

	free(lawn);

	return 0;
}

잡담

  • 더블 포인터 안 쓰고 하려고 했는데 머리가 딸려서 -_-;;;;

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:30:42
Processing time 0.0115 sec