PersonalCorpus 版 (精华区)
41715 2002-10-15 03:52:38 Accepted
1247 C++ 00:00.00 396K Big Guava
int main()
{
#ifndef ONLINE_JUDGE
freopen("c:\\0acm\\zju\\i1247","r",stdin);
freopen("c:\\0acm\\zju\\o1247","w",stdout);
#endif
int i,j,k,t=0,n,ne,e,se;
char s[8000];
double x,y;
while (1) {
gets(s);
if (strcmp(s,"END")==0) break; else t++;
i=0; e=0; se=0; n=0; ne=0;
while(1) {
sscanf(s+i,"%d",&k);
while (isdigit(s[i])) i++;
if ((s[i]=='N')&&(!isalpha(s[i+1]))) n+=k;
if ((s[i]=='E')&&(!isalpha(s[i+1]))) e+=k;
if ((s[i]=='S')&&(!isalpha(s[i+1]))) n-=k;
if ((s[i]=='W')&&(!isalpha(s[i+1]))) e-=k;
if ((s[i]=='N')&&(s[i+1]=='E')) ne+=k;
if ((s[i]=='S')&&(s[i+1]=='E')) se+=k;
if ((s[i]=='N')&&(s[i+1]=='W')) se-=k;
if ((s[i]=='S')&&(s[i+1]=='W')) ne-=k;
while (isalpha(s[i])) i++;
if (s[i]=='.') break; else i++;
}
x=e+(ne+se)/1.41421356237309504880;
y=n+(ne-se)/1.41421356237309504880;
printf("Map #%d\n",t);
printf("The treasure is located at (%.3lf,%.3lf).\n",x,y);
printf("The distance to the treasure is %.3lf.\n\n",
sqrt(x*x+y*y));
}
}
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.420毫秒