Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 자료구조
- 우선순위 큐
- 수학
- c++
- 스택
- BFS
- Unreal Engine 5
- DFS
- 누적 합
- 브루트포스
- 그래프
- 트리
- ue5
- 시뮬레이션
- 알고리즘
- 정렬
- 유니티
- VR
- 백준
- 구현
- 재귀
- XR Interaction Toolkit
- Team Fortress 2
- 문자열
- 다익스트라
- 투 포인터
- 그리디 알고리즘
- 다이나믹 프로그래밍
- 유니온 파인드
- 백트래킹
Archives
- Today
- Total
1일1알
백준 1063번 킹 C++ 본문
명령에 따라 직접 움직여보면서 문제를 해결하였다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
using namespace std;
using ll = long long;
int dRow[8] = { -1,-1, 0, 1, 1, 1, 0,-1 };
int dCol[8] = { 0, 1, 1, 1, 0,-1,-1,-1 };
string GetNextPos(const string &str, const string &moveStr) {
string nextPos = "";
if (moveStr == "T") {
nextPos += str[0];
nextPos += str[1] + 1;
}
else if (moveStr == "RT") {
nextPos += str[0] + 1;
nextPos += str[1] + 1;
}
else if (moveStr == "R") {
nextPos += str[0] + 1;
nextPos += str[1];
}
else if (moveStr == "RB") {
nextPos += str[0] + 1;
nextPos += str[1] - 1;
}
else if (moveStr == "B") {
nextPos += str[0];
nextPos += str[1] - 1;
}
else if (moveStr == "LB") {
nextPos += str[0] - 1;
nextPos += str[1] - 1;
}
else if (moveStr == "L") {
nextPos += str[0] - 1;
nextPos += str[1];
}
else {
nextPos += str[0] - 1;
nextPos += str[1] + 1;
}
return nextPos;
}
bool isOutOfBoard(string str) {
if ((str[0] < 'A' || str[0]>'H') ||
(str[1] < '1' || str[1]>'8')) {
return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string king, stone;
int n;
cin >> king >> stone >> n;
for (int i = 0; i < n; i++) {
string moveStr;
cin >> moveStr;
string nextKingPos = GetNextPos(king, moveStr);
if (isOutOfBoard(nextKingPos)) continue;
if (nextKingPos == stone) {
string nextStonePos = GetNextPos(stone, moveStr);
if (isOutOfBoard(nextStonePos)) continue;
king = nextKingPos;
stone = nextStonePos;
}
else king = nextKingPos;
}
cout << king << "\n" << stone;
};
'알고리즘' 카테고리의 다른 글
백준 1113번 수영장 만들기 C++ (0) | 2022.04.14 |
---|---|
백준 1195번 킥다운 C++ (0) | 2022.04.12 |
백준 1205번 등수 구하기 C++ (0) | 2022.04.10 |
백준 6603번 로또 C++ (0) | 2022.04.09 |
백준 16236번 아기 상어 C++ (0) | 2022.04.07 |