#include #include #include #include char s[10000]; void Rob() { char *q,*w, d[100]; int l; double x,y,sq; x=0; y=0; sq=sqrt(0.5); w=strchr(s,'.'); w[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; } printf("You can go to (%.3f,%.3f), the distance is %.3f steps.\n", x,y,sqrt(x*x+y*y)); } int main() { while (1) { fgets(s,1000,stdin); if (strcmp(s,"END\n")==0) break; Rob(); } return 0; }