Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
输入处理得不够严谨吧,我改了一下就可以AC了In Reply To:Re:我已经考虑了-0.000了!实在是找不出错那了?郁闷! Posted by:shunan at 2005-10-18 21:57:29 #include<stdio.h> #include<string.h> #include<math.h> #define pi 3.1415926535 char s[210],ss[3],s1[8][3]={"N","S","W","E","NW","NE","SE","SW"}; double s2[8]={pi/2,pi*3/2,pi,0,pi*3/4,pi/4,pi*7/4,pi*5/4}; int n,count; double d,x,y; void go_head(int dd) { int i; for(i=0;i<8;i++) if(strcmp(ss,s1[i])==0) { y+=dd*sin(s2[i]); x+=dd*cos(s2[i]); break; } } int main() { int i,test=0,di,dd; while(gets(s)!=NULL) { if(strcmp(s,"END")==0)break; test++; x=y=0.0; di=0;count=0; for(i=0;;i++) { if(s[i]==','||s[i]=='.') { ss[count++]='\0'; go_head(di); di=0;count=0; if(s[i]=='.')break; continue; } if(s[i]>='0'&&s[i]<='9') { dd=s[i]-'0'; di=di*10+dd;continue; } if(s[i]>='A'&&s[i]<='Z') { ss[count++]=s[i]; } } printf("Map #%d\n",test); d=sqrt(x*x+y*y); if(fabs(x)<1e-5)x=0.0; if(fabs(y)<1e-5)y=0.0; printf("The treasure is located at (%.3lf,%.3lf).\n",x,y); printf("The distance to the treasure is %.3lf.\n\n",d); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator