Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstring>
- #include <cmath>
- #include <cstdio>
- using namespace std;
- int main()
- {
- string red;
- double y;
- int i, ns=0, we=0, finalNs=0, finalWe=0;
- getline(cin, red);
- for(i=0; i<red.length(); i++)
- {
- ns = 0; we = 0;
- if(red[i]=='n')
- {
- if(isdigit(red[i+1])) ns += red[i+1]-'0';
- if(isdigit(red[i+2])){ns*=10; ns += red[i+2]-'0'; }
- }
- if(red[i]=='s')
- {
- if(isdigit(red[i+1])) ns -= red[i+1]-'0';
- if(isdigit(red[i+2])) {ns*=10; ns -= red[i+2]-'0'; }
- }
- if(red[i]=='w')
- {
- if(isdigit(red[i+1])) we += red[i+1]-'0';
- if(isdigit(red[i+2])){we*=10; we += red[i+2]-'0'; }
- }
- if(red[i]=='e')
- {
- if(isdigit(red[i+1])) we -= red[i+1]-'0';
- if(isdigit(red[i+2])){we*=10; we -= red[i+2]-'0'; }
- }
- finalNs+=ns;
- finalWe+=we;
- }
- y = sqrt(fabs(finalNs*finalNs) + fabs(finalWe*finalWe));
- printf ("%.2f", y);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment