구현_2번_왕실의 나이트

·2022년 6월 24일
0

이코테_알고리즘

목록 보기
23/23

코드


using namespace std;
#include <iostream>
#include <vector>
#include <string>


int main()
{
	// shift alt 로 동일한 행 내려가기 가능!
	string s;
	cin >> s;

	// 두 문자라고 했으므로. 
	int posX = s[0] - 'a';
	int posY = s[1] - '1';


	cout << posX << " " << posY << endl;

	// [x , y] 
	// 오른쪽으로 가면,,, 0, + 1
	// 왼쪽으로 가면,,, 0 , -1 
	// 위 로 가면,,, -1 , 0
	// 아래로 가면,,, +1 , 0

	// 움직일 수 있는 경우의 수 8가지 임. 
	
	vector< pair<int, int> >v = { { -2,1 }, { -2 , -1}, {2 , 1}, { 2 , -1}
								, {  1, -2 } , { -1 , -2} , { 1 , 2 } , { -1 , 2} };

	// 0 , 0 에서  7 , 7 까지의 범위로 진행하자.
	int cnt = 0;
	for (auto iter : v)
	{
		//총 8번을 돌면서,,, 이동할 수 있을 경우만 카운팅함.
		if (iter.first + posX >= 0
			&& iter.first + posX <= 7
			&& iter.second + posY >= 0
			&& iter.second + posY <= 7)
		{
			++cnt;
		}
	}

	cout << cnt;
}
profile
🔥🔥🔥

0개의 댓글