#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,x2,y2; int leni; int xo,yo,lo; len2=sqrt((long double)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']; y2+=(pathx[(unsigned int)'N']-pathx[(unsigned int)'S']); x=path[(unsigned int)'E']-path[(unsigned int)'W']; x2+=(pathx[(unsigned int)'E']-pathx[(unsigned int)'W']); xo=(x+len2*x2)*2000; yo=(y+len2*y2)*2000; /* lo=sqrt(y*y+x*x)*2000; */ lo=sqrt(2000*2000*(x*x+y*y+(x2*x2+y2*y2)/2+2*len2*(x*x2+y*y2))); xo=(xo+(xo>=0 ? +1 : -1))/2; yo=(yo+(yo>=0 ? +1 : -1))/2; lo=(lo+(lo>=0 ? +1 : -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; }