forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogo.cpp
51 lines (40 loc) · 1.01 KB
/
logo.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
#include <iostream>
#include <cmath>
using namespace std;
double PI = M_PI;
int dist(double x, double y) {
double total = pow(x, 2) + pow(y, 2);
total = sqrt(total);
return round(total);
}
int main() {
int cases;
cin >> cases;
for(int i = 0; i < cases; i++) {
double x = 0;
double y = 0;
int angle = 0;
int commands;
cin >> commands;
for(int j = 0; j < commands; j++) {
string cmd;
int dist;
cin >> cmd >> dist;
if(cmd == "lt") {
angle += dist;
}
if(cmd == "rt") {
angle -= dist;
}
if(cmd == "fd") {
x += dist * sin(angle * (PI / 180));
y += dist * cos(angle * (PI / 180));
}
if(cmd == "bk") {
x -= dist * sin(angle * (PI / 180));
y -= dist * cos(angle * (PI / 180));
}
}
cout << dist(x, y) << endl;
}
}