Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- #include <sstream>
- using namespace std;
- int main()
- {
- double x=0,y=0;
- string inp;
- while(true)
- {
- cin >> inp;
- if(inp[0]=='*')
- {
- break;
- }
- stringstream geek(inp);
- int a=0;
- geek >> a;
- int l= inp.length();
- if(inp[l-1]=='N')
- {
- y+=a;
- }
- if(inp[l-1]=='S')
- {
- y-=a;
- }
- if(inp[l-1]=='E')
- {
- if(inp[l-2]=='N')
- {
- y+=a/(sqrt(2));
- x+=a/(sqrt(2));
- }
- else if(inp[l-2]=='S')
- {
- y-=a/(sqrt(2));
- x+=a/(sqrt(2));
- }
- else
- {
- x+=a;
- }
- }
- if(inp[l-1]=='W')
- {
- if(inp[l-2]=='N')
- {
- y+=a/(sqrt(2));
- x-=a/(sqrt(2));
- }
- else if(inp[l-2]=='S')
- {
- y-=a/(sqrt(2));
- x-=a/(sqrt(2));
- }
- else
- {
- x-=a;
- }
- }
- }
- double z=sqrt((pow(x,2))+(pow(y,2)));
- cout << fixed;
- cout << setprecision(3) << x << " " << y << "\n" << z;
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement