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

常见的回答是:“你的程序是错的”

Posted by frkstyc at 2005-05-22 22:15:09 on Problem 1473
In Reply To:奇怪...同一个程序用c++交就ac,用g++交就wa了……hawk大哥怎么回事啊? Posted by:wangchen1ren at 2005-05-22 22:14:29
> #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:
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