#include #include int d,i,j; float x,y,s2,p; char s[256], c[4]; int main() { s2 = sqrt(2); while(1){ gets(s); if((s[0] == 'E') && (s[1] == 'N') && (s[2] == 'D') && (s[3] == 0)) break; x = y = i = 0; while(1){ sscanf(&s[i], "%d%c%c", &d, &c[0], &c[1]); while((s[i] >= '0') && (s[i] <= '9')) i++; i += 2; if((c[1] != ',') && (c[1] != '.')){ c[2] = s[i]; i++; j = 2; }else j = 1; switch(c[0]){ case 'N': if(c[1] == 'E'){ p = (float)d / s2; y += p; x += p; }else if(c[1] == 'W'){ p = (float)d / s2; y += p; x -= p; }else y += d; break; case 'E': x += d; break; case 'S': if(c[1] == 'E'){ p = (float)d / s2; x += p; y -= p; }else if(c[1] == 'W'){ p = (float)d / s2; y -= p; x -= p; }else y -= d; break; case 'W': x -= d; break; } if(c[j] == '.'){ if((x < 0) && (x >= -0.0001)) x = 0; if((y < 0) && (y >= -0.0001)) y = 0; printf("You can go to (%.3f,%.3f), the distance is %.3f steps.\n", x, y, sqrt(x*x + y*y)); break; } } } return(0); }