#include #include #include #include #include #include #define NDEBUG 1 static long double path[250]; static long double pathx[250]; int main(void) { int i; char c,c2; long double len,x,y,len2; int leni; int xo,yo,lo; len2=sqrt(0.5); for (;;) { for (;;) { retry: c=getchar(); if (c=='.') break; if (c=='E') break; if (c==',') goto retry; assert(isdigit(c)); ungetc(c,stdin); i=scanf("%d",&leni); len=leni; assert(i==1); c=getchar(); assert(c=='N' || c=='S' || c=='E' || c=='W'); c2=getchar(); assert(c2=='N' || c2=='S' || c2=='E' || c2=='W' || c2==',' || c2=='.'); if (c2=='N' || c2=='S' || c2=='E' || c2=='W') { pathx[(unsigned int)c]+=len; pathx[(unsigned int)c2]+=len; } else { path[(unsigned int)c]+=len; ungetc(c2,stdin); } } if (c=='E') { break; } c=getchar(); assert(c=='\n'); y=path[(unsigned int)'N']-path[(unsigned int)'S']; y+=len2*(pathx[(unsigned int)'N']-pathx[(unsigned int)'S']); x=path[(unsigned int)'E']-path[(unsigned int)'W']; x+=len2*(pathx[(unsigned int)'E']-pathx[(unsigned int)'W']); xo=x*2000; yo=y*2000; lo=sqrt(y*y+x*x)*2000; xo=(xo+1)/2; yo=(yo+1)/2; lo=(lo+1)/2; printf("You can go to (%d.%03d,%d.%03d), the distance is %d.%03d steps.\n", xo/1000,abs(xo%1000),yo/1000,abs(yo%1000),lo/1000,abs(lo%1000)); path[(unsigned int)'N']=0; path[(unsigned int)'S']=0; path[(unsigned int)'E']=0; path[(unsigned int)'W']=0; pathx[(unsigned int)'N']=0; pathx[(unsigned int)'S']=0; pathx[(unsigned int)'E']=0; pathx[(unsigned int)'W']=0; } return 0; }