BOJ : https://www.acmicpc.net/problem/1063
시뮬레이션 문제입니다
문자 각각 따로따로 구현하면 너무 코드가 길어지고 보기 안좋으니
간단하게 스트링 받아서 비교한 후 바로 사용할 수 있도록 하시면 편하게 해결할 수 있습니다.
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <cmath>
#include <limits>
#include <cstring>
#include <string>
using namespace std;
// R L B T RT LT RB LB
int ml[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
int mr[8] = { 0, 0, -1, 1 ,1 ,1, -1, -1 };
string arr[8] = { "R","L","B","T","RT","LT","RB","LB" };
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int tc;
string str;
pair<int, int> k, d;
getline(cin, str);
k.first = str[0] - 'A', k.second = str[1]-'0', d.first = str[3] - 'A', d.second = str[4]-'0';
if (str.size() == 7) tc = str[6]-'0';
else tc = (str[6]-'0') * 10 + (str[7]-'0');
while (tc--) {
getline(cin, str);
int check;
int l = k.first, r = k.second;
for (int i = 0; i < 8; i++) { if (str.compare(arr[i]) == 0) { check = i, l += ml[i], r += mr[i]; break; } }
if (l >= 0 && l < 8 && r >= 1 && r <= 8) {
if (!(l == d.first && r == d.second)) {
k.first = l, k.second = r;
}
else {
int df = d.first + ml[check];
int ds = d.second + mr[check];
if (df >= 0 && df < 8 && ds >= 1 && ds <= 8)
d.first = df, d.second = ds, k.first = l, k.second = r;
}
}
}
char lastk = k.first + 'A';
char lastd = d.first + 'A';
cout << lastk << k.second << endl;
cout << lastd << d.second << endl;
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'algorithm > BOJ' 카테고리의 다른 글
BOJ 2699번 격자점 컨벡스헐 (0) | 2020.04.07 |
---|---|
BOJ 1708번 볼록 껍질 (0) | 2020.04.07 |
BOJ 14499번 주사위 굴리기 (0) | 2020.03.14 |
BOJ 14503번 로봇 청소기 (0) | 2020.03.13 |
BOJ 3709번 레이저빔은 어디로 (0) | 2020.03.13 |