velimir

Map

Mar 28th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <cstdio>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     string red;
  12.     double y;
  13.     int i, ns=0, we=0, finalNs=0, finalWe=0;
  14.     getline(cin, red);
  15.     for(i=0; i<red.length(); i++)
  16.     {
  17.         ns = 0; we = 0;
  18.         if(red[i]=='n')
  19.         {
  20.             if(isdigit(red[i+1])) ns += red[i+1]-'0';
  21.             if(isdigit(red[i+2])){ns*=10; ns += red[i+2]-'0'; }
  22.         }
  23.         if(red[i]=='s')
  24.         {
  25.             if(isdigit(red[i+1])) ns -= red[i+1]-'0';
  26.             if(isdigit(red[i+2])) {ns*=10; ns -= red[i+2]-'0'; }
  27.         }
  28.         if(red[i]=='w')
  29.         {
  30.             if(isdigit(red[i+1])) we += red[i+1]-'0';
  31.             if(isdigit(red[i+2])){we*=10; we += red[i+2]-'0'; }
  32.         }
  33.         if(red[i]=='e')
  34.         {
  35.             if(isdigit(red[i+1])) we -= red[i+1]-'0';
  36.             if(isdigit(red[i+2])){we*=10; we -= red[i+2]-'0'; }
  37.         }
  38.         finalNs+=ns;
  39.         finalWe+=we;
  40.     }
  41.     y = sqrt(fabs(finalNs*finalNs) + fabs(finalWe*finalWe));
  42.     printf ("%.2f", y);
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment