#include #include #include #include char s[10000]; void Rob() { char *q,*w, d[100]; char xx[100],yy[100],*xxs,*yys; int l; double x,y,sq; x=0; y=0; sq=sqrt(0.5); w=strchr(s,'.'); w[0]=','; w[1]=0; for (q=s;;) { w=strchr(q,','); if (w==NULL) break; w[0]=0; sscanf(q,"%d%s",&l,d); if (strncmp(d,"NE",2)==0) { x+=l*sq; y+=l*sq; } else if (strncmp(d,"SE",2)==0) { x+=l*sq; y-=l*sq; } else if (strncmp(d,"SW",2)==0) { x-=l*sq; y-=l*sq; } else if (strncmp(d,"NW",2)==0) { x-=l*sq; y+=l*sq; } else if (strncmp(d,"N",1)==0) { y+=l; } else if (strncmp(d,"S",1)==0) { y-=l; } else if (strncmp(d,"E",1)==0) { x+=l; } else if (strncmp(d,"W",1)==0) { x-=l; } q=w+1; } sprintf(d,"%.3f",sqrt(x*x+y*y)); if (strcmp(d,"-0.000")==0) q=d+1; else q=d; sprintf(xx,"%.3f",x); if (strcmp(xx,"-0.000")==0) xxs=xx+1;else xxs=xx; sprintf(yy,"%.3f",y); if (strcmp(yy,"-0.000")==0) yys=yy+1;else yys=yy; printf("You can go to (%s,%s), the distance is %s steps.\n", xxs,yys,q); } int main() { while (1) { fgets(s,1000,stdin); if (strncmp(s,"END",3)==0) break; Rob(); } return 0; }