https://www.acmicpc.net/problem/1063
#include <iostream>
#include <string>
using namespace std;
struct MOVE { int x, y; };
MOVE mv[8] = { {1,0}, {-1,0}, {0,-1}, {0,1}, {1,1}, {-1,1}, {1,-1}, {-1,-1} };
pair<int, int> king;
pair<int, int> stone;
int n;
int change(char ch) {
if (ch == 'A') return 1;
else if (ch == 'B') return 2;
else if (ch == 'C') return 3;
else if (ch == 'D') return 4;
else if (ch == 'E') return 5;
else if (ch == 'F') return 6;
else if (ch == 'G') return 7;
else if (ch == 'H') return 8;
}
char change2(int ch) {
if (ch == 1) return 'A';
else if (ch == 2) return 'B';
else if (ch == 3) return 'C';
else if (ch == 4) return 'D';
else if (ch == 5) return 'E';
else if (ch == 6) return 'F';
else if (ch == 7) return 'G';
else if (ch == 8) return 'H';
}
int main(void) {
string tmp;
cin >> tmp;
char i = tmp[0];
int j = tmp[1] - '0';
int ii = change(i);
king = { ii,j };
cin >> tmp;
ii = change(tmp[0]);
stone = { ii,tmp[1]-'0'};
cin >> n;
for (int i = 0; i < n; i++) {
string cmd;
cin >> cmd;
int movei = king.first;
int movej = king.second;
if (cmd == "R") {
movei += mv[0].x;
movej += mv[0].y;
if (!(movei >= 1 && movei <= 8 && movej >= 1 && movej <= 8)) continue;
if (movei == stone.first && movej == stone.second) {
int tmp_movei = stone.first + mv[0].x;
int tmp_movej = stone.second + mv[0].y;
if (!(tmp_movei >= 1 && tmp_movei <= 8 && tmp_movej >= 1 && tmp_movej <= 8)) continue;
stone = { tmp_movei,tmp_movej };
}
king = { movei,movej };
}
else if (cmd == "L") {
movei += mv[1].x;
movej += mv[1].y;
if (!(movei >= 1 && movei <= 8 && movej >= 1 && movej <= 8)) continue;
if (movei == stone.first && movej == stone.second) {
int tmp_movei = stone.first + mv[1].x;
int tmp_movej = stone.second + mv[1].y;
if (!(tmp_movei >= 1 && tmp_movei <= 8 && tmp_movej >= 1 && tmp_movej <= 8)) continue;
stone = { tmp_movei,tmp_movej };
}
king = { movei,movej };
}
else if (cmd == "B") {
movei += mv[2].x;
movej += mv[2].y;
if (!(movei >= 1 && movei <= 8 && movej >= 1 && movej <= 8)) continue;
if (movei == stone.first && movej == stone.second) {
int tmp_movei = stone.first + mv[2].x;
int tmp_movej = stone.second + mv[2].y;
if (!(tmp_movei >= 1 && tmp_movei <= 8 && tmp_movej >= 1 && tmp_movej <= 8)) continue;
stone = { tmp_movei,tmp_movej };
}
king = { movei,movej };
}
else if (cmd == "T") {
movei += mv[3].x;
movej += mv[3].y;
if (!(movei >= 1 && movei <= 8 && movej >= 1 && movej <= 8)) continue;
if (movei == stone.first && movej == stone.second) {
int tmp_movei = stone.first + mv[3].x;
int tmp_movej = stone.second + mv[3].y;
if (!(tmp_movei >= 1 && tmp_movei <= 8 && tmp_movej >= 1 && tmp_movej <= 8)) continue;
stone = { tmp_movei,tmp_movej };
}
king = { movei,movej };
}
else if (cmd == "RT") {
movei += mv[4].x;
movej += mv[4].y;
if (!(movei >= 1 && movei <= 8 && movej >= 1 && movej <= 8)) continue;
if (movei == stone.first && movej == stone.second) {
int tmp_movei = stone.first + mv[4].x;
int tmp_movej = stone.second + mv[4].y;
if (!(tmp_movei >= 1 && tmp_movei <= 8 && tmp_movej >= 1 && tmp_movej <= 8)) continue;
stone = { tmp_movei,tmp_movej };
}
king = { movei,movej };
}
else if (cmd == "LT") {
movei += mv[5].x;
movej += mv[5].y;
if (!(movei >= 1 && movei <= 8 && movej >= 1 && movej <= 8)) continue;
if (movei == stone.first && movej == stone.second) {
int tmp_movei = stone.first + mv[5].x;
int tmp_movej = stone.second + mv[5].y;
if (!(tmp_movei >= 1 && tmp_movei <= 8 && tmp_movej >= 1 && tmp_movej <= 8)) continue;
stone = { tmp_movei,tmp_movej };
}
king = { movei,movej };
}
else if (cmd == "RB") {
movei += mv[6].x;
movej += mv[6].y;
if (!(movei >= 1 && movei <= 8 && movej >= 1 && movej <= 8)) continue;
if (movei == stone.first && movej == stone.second) {
int tmp_movei = stone.first + mv[6].x;
int tmp_movej = stone.second + mv[6].y;
if (!(tmp_movei >= 1 && tmp_movei <= 8 && tmp_movej >= 1 && tmp_movej <= 8)) continue;
stone = { tmp_movei,tmp_movej };
}
king = { movei,movej };
}
else if (cmd == "LB") {
movei += mv[7].x;
movej += mv[7].y;
if (!(movei >= 1 && movei <= 8 && movej >= 1 && movej <= 8)) continue;
if (movei == stone.first && movej == stone.second) {
int tmp_movei = stone.first + mv[7].x;
int tmp_movej = stone.second + mv[7].y;
if (!(tmp_movei >= 1 && tmp_movei <= 8 && tmp_movej >= 1 && tmp_movej <= 8)) continue;
stone = { tmp_movei,tmp_movej };
}
king = { movei,movej };
}
}
char ch = change2(king.first);
cout << ch << king.second << " ";
ch = change2(stone.first);
cout << ch << stone.second << endl;
}
'백준 알고리즘 > 시뮬레이션' 카테고리의 다른 글
보이저 1호 (0) | 2022.04.06 |
---|---|
거북이 C++ (0) | 2022.04.05 |
캐슬 디펜스 C++ (0) | 2022.03.07 |
어른 상어 C++ (0) | 2021.04.22 |
백준 이차원 배열과 연산 C++ (0) | 2019.10.17 |