Advertisement
Josif_tepe

Untitled

Feb 12th, 2021
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #include <iostream>
  2. #include<ctype.h>
  3. #include<cmath>
  4. #include<iomanip>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     string n;
  10.     getline(cin,n);
  11.     double a,b,c,d;
  12.     a=0;
  13.     b=0;
  14.     c=0;
  15.     d=0;
  16.     double x,y,z;
  17.     for(int i=0; i<n.size(); i++)
  18.     {
  19.         if(n[i]=='n' && isdigit(n[i+1])==1 && isdigit(n[i+2])==1 )
  20.         {
  21.             a=a+(n[i+1]-'0')*10+(n[i+2]-'0');
  22.         }
  23.         else if(n[i]=='n' && isdigit(n[i+1])==1 )
  24.         {
  25.             a=a+(n[i+1]-'0');
  26.         }
  27.         if(n[i]=='s' && isdigit(n[i+1])==1 && isdigit(n[i+2])==1 )
  28.         {
  29.             b=b+(n[i+1]-'0')*10+(n[i+2]-'0');
  30.         }
  31.         else if(n[i]=='s' && isdigit(n[i+1])==1 )
  32.         {
  33.             b=b+(n[i+1]-'0');
  34.         }
  35.         if(n[i]=='w' && isdigit(n[i+1])==1 && isdigit(n[i+2])==1 )
  36.         {
  37.             c=c+(n[i+1]-'0')*10+(n[i+2]-'0');
  38.         }
  39.         else if(n[i]=='w' && isdigit(n[i+1])==1 )
  40.         {
  41.             c=c+(n[i+1]-'0');
  42.         }
  43.         if(n[i]=='e' && isdigit(n[i+1])==1 && isdigit(n[i+2])==1 )
  44.                 {
  45.                     d=d+(n[i+1]-'0')*10+(n[i+2]-'0');
  46.                 }
  47.                 else if(n[i]=='e' && isdigit(n[i+1])==1 )
  48.                 {
  49.                     d=d+(n[i+1]-'0');
  50.                 }
  51.             }
  52.             x=a-b;
  53.             y=c-d;
  54.             z=sqrt(pow(a-b,2)+pow(c-d,2));
  55.             cout<<fixed<<setprecision(2)<<z;
  56.             return 0;
  57.         }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement