-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8911거북이.cpp
77 lines (55 loc) · 1.18 KB
/
8911거북이.cpp
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <bits/stdc++.h>
using namespace std;
int N;
int x = 0, y = 0;
int maxx = 0, minx = 0, maxy = 0, miny = 0;
int direction = 0;
int sum = 0;
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int main() {
//거북이의 위치 기록 / 거북이가 지나간 가로세로 기록
cin >> N;
for (int i = 0; i < N; i++) {
x = 0, y = 0;
maxx = 0, minx = 0, maxy = 0, miny =0;
direction = 0; //0=북쪽, 1= 동쪽, 2= 남쪽, 3=서쪽
sum = 0;
string str;
cin >> str;
for (int j = 0; j < str.size(); j++) {
if (str[j] == 'L' || str[j] == 'R') {
if (str[j] == 'L') {
direction = (direction + 3) % 4;
}
else if (str[j] == 'R') {
direction = (direction + 1) % 4;
}
continue;
}
else {
if (str[j] == 'F') {
x += dx[direction];
y += dy[direction];
}
else if (str[j] == 'B')
{
x -= dx[direction];
y -= dy[direction];
}
maxx = max(maxx, x);
minx = min(minx, x);
maxy = max(maxy, y);
miny = min(miny, y);
}
}
sum = (maxx - minx) * (maxy - miny);
cout << sum<<"\n";
}
return 0;
}