📄 1595.cpp
字号:
/* This Code is Submitted by wywcgs for Problem 1595 on 2005-10-02 at 14:48:09 */
#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
double treax, treay, m, dis;
int step, t = 1;
int i, flag;
char dir[4], map[16];
while(1) {
treax = 0;
treay = 0;
while(1) {
if(scanf("%d", &step) == 0) {
gets(map);
return 0;
} else {
flag = 0;
for(i = 0; ; i++) {
dir[i] = getchar();
if(dir[i] == ',') {
dir[i] = 0;
break;
} else if(dir[i] == '.') {
dir[i] = 0;
flag = 1;
break;
}
}
if(!strcmp(dir, "N")) {
treay += step;
} else if(!strcmp(dir, "S")) {
treay -= step;
} else if(!strcmp(dir, "W")) {
treax -= step;
} else if(!strcmp(dir, "E")) {
treax += step;
} else if(!strcmp(dir, "NW")) {
m = sqrt((double)step*step/2);
treay += m;
treax -= m;
} else if(!strcmp(dir, "NE")) {
m = sqrt((double)step*step/2);
treay += m;
treax += m;
} else if(!strcmp(dir, "SW")) {
m = sqrt((double)step*step/2);
treay -= m;
treax -= m;
} else {
m = sqrt((double)step*step/2);
treay -= m;
treax += m;
}
if(flag == 1) {
break;
}
}
}
printf("Map #%d\n", t);
t++;
if(fabs(treax) < 1e-6){
treax = 0;
}
if(fabs(treay) < 1e-6) {
treay = 0;
}
printf("The treasure is located at (%.3lf,%.3lf).\n", treax, treay);
dis = sqrt(treax*treax+treay*treay);
printf("The distance to the treasure is %.3lf.\n\n", dis);
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -