U E D R , A S I H C RSS

Wheres Waldorf/Celfin

~cpp
#include <iostream>
#include <cstdlib>
using namespace std;

int testcase, testNum;
char list[50][50];
char testlist[20][50];
char temp[255];
int row, col, i, j, k, n;

bool check(int ax, int ay, char *temp)
{
	int x=ax; int y=ay;
	int length = strlen(temp);
	//북 0, -1
	for(n=0; n<length && y>=0; n++, y--)
	{
		if(list[x][y]!=temp[n])
			break;
		if(n==length-1)
			return true;
	}
	//북동 +1, -1
	x=ax; y=ay;
	for(n=0; n<length && x<row && y>=0; n++, x++, y--)
	{
		if(list[x][y]!=temp[n])
			break;
		if(n==length-1)
			return true;
	}
	//동 +1, 0
	x=ax; y=ay;
	for(n=0; n<length && x<row; n++, x++)
	{
		if(list[x][y]!=temp[n])
			break;
		if(n==length-1)
			return true;
	}
	//남동 +1, +1
	x=ax; y=ay;
	for(n=0; n<length && x<row && y<col; n++, x++, y++)
	{
		if(list[x][y]!=temp[n])
			break;
		if(n==length-1)
			return true;
	}
	//남 0, +1
	x=ax; y=ay;
	for(n=0; n<length && y<col; n++, y++)
	{
		if(list[x][y]!=temp[n])
			break;
		if(n==length-1)
			return true;
	}
	//남서 -1, +1
	x=ax; y=ay;
	for(n=0; n<length && x>=0 && y<col; n++, x--, y++)
	{
		if(list[x][y]!=temp[n])
			break;
		if(n==length-1)
			return true;
	}
	//서 -1, 0
	x=ax; y=ay;
	for(n=0; n<length && x>=0; n++, x--)
	{
		if(list[x][y]!=temp[n])
			break;
		if(n==length-1)
			return true;
	}
	//북서 -1, -1
	x=ax; y=ay;
	for(n=0; n<length && x>=0 && y>=0; n++, x--, y--)
	{
		if(list[x][y]!=temp[n])
			break;
		if(n==length-1)
			return true;
	}
	return false;
}

void calculate()
{
	bool exitCond;
	for(k=0; k<testNum; k++)
	{
		exitCond=false;
		for(i=0; i<row; i++)
		{
			for(j=0; j<col; j++)
			{
				if(list[i][j]==testlist[k][0])
				{
					if(check(i, j, testlist[k]))
					{
						cout <<i+1 <<" " <<j+1 <<endl;
						exitCond=true;
						break;
					}
				}
			}
			if(exitCond)
				break;
		}
	}
}

int main()
{
	cin >> testcase;
	cin.getline(temp, 255);
	while(testcase--)
	{
		cin.getline(temp, 255);
		cin >> row >> col;
		for(i=0; i<row; i++)
		{
			for(j=0; j<col; j++)
			{
				cin>>list[i][j];
				if(list[i][j]>=65 && list[i][j]<=90)
					list[i][j] = list[i][j] + 32;
			}
		}
		cin >> testNum;
		cin.getline(temp, 255);
		for(i=0; i<testNum; i++)
		{
			cin.getline(testlist[i], 50);
			for(j=0; j<strlen(testlist[i]); j++)
			{
				if(testlist[i][j]>=65 && testlist[i][j]<=90)
					testlist[i][j] = testlist[i][j] + 32;
			}
		}

		calculate();
		if(testcase!=0)
			cout << endl;
	}

	return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:24
Processing time 0.0073 sec