| ||||||||||
| 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 | |||||||||
奇怪...同一个程序用c++交就ac,用g++交就wa了……hawk大哥怎么回事啊?#include <iostream>
#include <string.h>
#include <math.h>
static char ends[5]={"END"};
char s[200];
double x,y;
long dis,dx,dy,i,t=1;
main()
{
// freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
while (scanf("%s",s)!=EOF)
{
if (strcmp(s,ends)==0) break;
x=0.0;y=0.0;
dis=0;dx=0;dy=0;
i=0;
while (i<strlen(s))
{
if (s[i]=='N') dy=1;
else if (s[i]=='S') dy=-1;
else if (s[i]=='W') dx=-1;
else if (s[i]=='E') dx=1;
else if (s[i]==','||s[i]=='.')
{
if (dx==0||dy==0)
{
x+=double(dis)*double(dx);
y+=double(dis)*double(dy);
}
else
{
x+=double(dx)*double(dis)/sqrt(2.0);
y+=double(dy)*double(dis)/sqrt(2.0);
}
dis=0;dx=0;dy=0;
}
else
if (s[i]>='0'&&s[i]<='9')
{
dis=s[i]-'0';
while (s[i+1]>='0'&&s[i+1]<='9')
{
i++;
dis=dis*10+s[i]-'0';
}
}
i++;
}
printf("Map #%d\n",t++);
printf("The treasure is located at (%0.3lf,%0.3lf).\n",x,y);
printf("The distance to the treasure is %0.3lf.\n",sqrt(x*x+y*y));
printf("\n");
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator