Skip to content

Instantly share code, notes, and snippets.

@HyeonWooKim
Created December 11, 2016 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HyeonWooKim/b1013cc7a463c2479af6c9c55c877725 to your computer and use it in GitHub Desktop.
Save HyeonWooKim/b1013cc7a463c2479af6c9c55c877725 to your computer and use it in GitHub Desktop.
BOJ 1063 킹
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
class Node
{
public:
int x, y;
Node() {}
Node(string s)
{
x = s[0] - 'A'+1;
y = s[1] - '0';
}
};
int main()
{
string a, b;
//king - pawn
int c, xdir[8] = { -1,1,0,0,-1,1,-1,1}, ydir[8] = { 0,0,1,-1,-1,-1,1,1 };
int dir[8][2] = { {1, 0},{-1,0},{0,-1},{0,1},{1,1},{-1,1},{1,-1},{-1,-1} };
string cmd[] = { "R","L","B","T","RT","LT","RB","LB" };
cin >> a >> b >> c;
Node k(a), p(b);
for (int i = 0; i < c; i++)
{
string d;
cin >> d;
for (int i = 0; i < 8; i++)
{
if (d == cmd[i])
{
int knx = k.x + dir[i][0], kny = k.y + dir[i][1], pnx = p.x + dir[i][0], pny = p.y + dir[i][1];
if (knx < 1 || kny < 1 || knx > 8 || kny > 8) continue;
if (k.x - p.x == xdir[i] && k.y - p.y == ydir[i])
{
if (pnx < 1 || pny < 1 || pnx > 8 || pny > 8) continue;
p.x = pnx, p.y = pny;
}
k.x = knx, k.y = kny;
}
}
}
printf("%c%c\n%c%c", k.x + 'A'-1, k.y + '0', p.x + 'A'-1, p.y + '0');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment