#include #include #include char line[300]; double S2; #define ER 0.0000001 int OneTask() { S2 = sqrt(2)/2; double x = 0; double y = 0; scanf("%s", line); if (line[0] == 'E') return 0; char* tok; for(tok = strtok(line, ",."); tok != NULL; tok = strtok(NULL, ",.")) { int step; sscanf(tok, "%d", &step); //printf("%s, %d\n", tok, step); int len = strlen(tok) - 2; switch(tok[len+1]) { case 'N': y+=step; break; case 'S': y-=step; break; case 'W': if (tok[len] == 'N') { y += step*S2; x -= step*S2; } else if(tok[len] == 'S') { y -= step*S2; x -= step*S2; } else x -= step; break; case 'E': if (tok[len] == 'N') { y += step*S2; x += step*S2; } else if(tok[len] == 'S') { y -= step*S2; x += step*S2; } else x += step; break; } } printf("You can go to (%.3f,%.3f), the distance is %.3f steps.\n", x+ER, y+ER, sqrt(x*x+y*y)+ER); return 1; } int main() { while(OneTask()) ; return 0; }