Advertisement
DarkTXYZ

PROG-1016: Treasure

Mar 28th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. double cal(double x,double y){
  6.     return sqrt(x*x + y*y);
  7. }
  8.  
  9. int main(){
  10.     string input;
  11.     double x = 0,y = 0;
  12.     int dis;
  13.     string direct;
  14.     cin >> dis >> direct;
  15.     while(dis>=1 and dis<=999){
  16.         double dist = (double)dis;
  17.         if(direct == "N")
  18.             y += dis;
  19.         else if(direct == "E")
  20.             x += dis;
  21.         else if(direct == "W")
  22.             x -= dis;
  23.         else if(direct == "S")
  24.             y -= dis;
  25.         else{
  26.             dist = dist/sqrt(2);
  27.             if(direct == "NE"){
  28.                 x += dist;
  29.                 y += dist;
  30.             }
  31.             else if(direct == "SE"){
  32.                 x += dist;
  33.                 y -= dist;
  34.             }
  35.             else if(direct == "SW"){
  36.                 x -= dist;
  37.                 y -= dist;
  38.             }
  39.             else if(direct == "NW"){
  40.                 x -= dist;
  41.                 y += dist;
  42.             }
  43.         }
  44.         cin >> dis >> direct;
  45.     }
  46.     printf("%.3f %.3f\n",x,y);
  47.     printf("%.3f",cal(x,y));
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement