forked from Autoratch/Thailand-Olympiad-in-Informatics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoi03_treasure.cpp
48 lines (43 loc) · 1.13 KB
/
toi03_treasure.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
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1e9 + 7
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
vector<string> s;
double x = 0,y = 0;
while(true)
{
string tm;
cin >> tm;
if(tm=="*") break;
s.push_back(tm);
}
for(int i = 0;i < s.size();i++)
{
double tmp = 0;
if(s[i][s[i].length()-2]>='A')
{
int mu = 1;
for(int j = s[i].length()-3;j >= 0;j--){ tmp+=(mu*(s[i][j]-'0')); mu*=10; }
tmp = (double)(tmp/sqrt(2.0));
if(s[i][s[i].length()-2]=='N') x+=tmp;
else x-=tmp;
if(s[i][s[i].length()-1]=='E') y+=tmp;
else y-=tmp;
}
else
{
int mu = 1;
for(int j = s[i].length()-2;j >= 0;j--){ tmp+=(mu*(s[i][j]-'0')); mu*=10; }
char c = s[i][s[i].length()-1];
if(c=='N') x+=tmp;
else if(c=='S') x-=tmp;
else if(c=='E') y+=tmp;
else y-=tmp;
}
}
cout << fixed;
cout << setprecision(3) << y << ' ' << x << endl << sqrt(x*x+y*y);
}