Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么一直WA啊,哪位高手给看一下我的代码吧?我试了好几组都没问题!谢谢了!!

Posted by shunan at 2005-10-18 21:36:05 on Problem 1473
#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(scanf("%s",s))
	{
		if(strcmp(s,"END")==0)break;
		test++;
		x=y=0.0;
		di=0;count=0;
		for(i=0;s[i]!='.';i++)
		{
			if(s[i]==',')
			{
				ss[count++]='\0';
				go_head(di);
				di=0;count=0;
				continue;
			}
			if(s[i]>=48&&s[i]<=57)
			{
				dd=s[i]-48;
				di=di*10+dd;continue;
			}
			if(s[i]>='A'&&s[i]<='Z')
			{
				ss[count++]=s[i];
			}
		}
		go_head(di);
		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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator