Advertisement
Slayerfeed

Treasure, that is what you are

Apr 4th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. #include <sstream>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. int main()
  10. {
  11.     double x=0,y=0;
  12.     string inp;
  13.  
  14.     while(true)
  15.     {
  16.  
  17.         cin >> inp;
  18.  
  19.         if(inp[0]=='*')
  20.         {
  21.             break;
  22.         }
  23.         stringstream geek(inp);
  24.         int  a=0;
  25.         geek >> a;
  26.         int l= inp.length();
  27.         if(inp[l-1]=='N')
  28.         {
  29.             y+=a;
  30.         }
  31.         if(inp[l-1]=='S')
  32.         {
  33.             y-=a;
  34.         }
  35.         if(inp[l-1]=='E')
  36.         {
  37.             if(inp[l-2]=='N')
  38.             {
  39.                 y+=a/(sqrt(2));
  40.                 x+=a/(sqrt(2));
  41.             }
  42.             else if(inp[l-2]=='S')
  43.             {
  44.                 y-=a/(sqrt(2));
  45.                 x+=a/(sqrt(2));
  46.             }
  47.             else
  48.             {
  49.                 x+=a;
  50.             }
  51.         }
  52.         if(inp[l-1]=='W')
  53.         {
  54.             if(inp[l-2]=='N')
  55.             {
  56.                 y+=a/(sqrt(2));
  57.                 x-=a/(sqrt(2));
  58.             }
  59.             else if(inp[l-2]=='S')
  60.             {
  61.                 y-=a/(sqrt(2));
  62.                 x-=a/(sqrt(2));
  63.             }
  64.             else
  65.             {
  66.                 x-=a;
  67.             }
  68.         }
  69.  
  70.     }
  71.  
  72.     double z=sqrt((pow(x,2))+(pow(y,2)));
  73.     cout << fixed;
  74.     cout << setprecision(3) << x << " " << y << "\n" << z;
  75.  
  76.     return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement