#include #include #include #include int main (void) { for (;;) { static char buf[256]; int e, n, ne, nw; const char *p; long double x, y; gets (buf); if (strcmp (buf, "END") == 0) break; e = 0; n = 0; ne = 0; nw = 0; p = buf; while (*p != '.') { unsigned v; v = 0; while (isdigit (*p)) v = 10 * v + *p++ - '0'; switch (*p++) { case 'N': if (*p == 'E') { p++; ne += v; } else if (*p == 'W') { p++; nw += v; } else n += v; break; case 'S': if (*p == 'E') { p++; nw -= v; } else if (*p == 'W') { p++; ne -= v; } else n -= v; break; case 'E': e += v; break; case 'W': e -= v; break; } if (*p == ',') p++; } x = e + (ne - nw) / M_SQRT2; y = n + (ne + nw) / M_SQRT2; printf ("You can go to (%.3f,%.3f), the distance is %.3f steps.\n", (double)x, (double)y, (double)hypotl (x, y)); } return EXIT_SUCCESS; }