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

whats Wrong ??

Posted by ACPC2 at 2006-07-17 23:39:59 on Problem 1473
#include<iostream>
#include<iomanip>
#include<string>
#include<cmath>
using namespace std;
int main()
{
    int n=0,t=0;
    float x=0,y=0;
    string s,d;
    while(cin>>s)
    {
         if(s[0]=='E')break;
         for(int i=0;i<s.size();i++)
         {
                 if(s[i]==','||s[i]=='.')
                 {
                      // process the solution
                      // cout<<n<<d<<endl;                         
                      if(d.size()==1)
                      {
                           if(d=="N")y=y+n;
                           if(d=="E")x=x+n;
                           if(d=="S")y=y-n;
                           if(d=="W")x=x-n;
                      }
                      
                      if(d.size()==2)
                      {
                           if(d=="NE"){y=y+sqrt(float(n*n)/2);x=x+sqrt(float(n*n)/2);}
                           if(d=="SE"){y=y-sqrt(float(n*n)/2);x=x+sqrt(float(n*n)/2);}
                           if(d=="SW"){y=y-sqrt(float(n*n)/2);x=x-sqrt(float(n*n)/2);}
                           if(d=="NW"){y=y+sqrt(float(n*n)/2);x=x-sqrt(float(n*n)/2);}
                      }

                      n=0;
                      d="";
                      continue;
                 }
                 if(s[i]>='0'&&s[i]<='9')
                 {
                        n=(n*10)+(s[i]-'0');                 
                        continue;
                 }
                 d+=" ";
                 d[d.size()-1]=s[i];
         }
         cout<<"Map #"<<t+1<<endl;
         cout<<fixed<<setprecision(3)<<"The treasure is located at ("<<x<<","<<y<<")."<<endl;
         cout<<fixed<<setprecision(3)<<"The distance to the treasure is "<<sqrt(x*x+y*y)<<"."<<endl;
         cout<<endl;
         x=0;
         y=0;
         t++;
    }   
    // cin>>t;
    
    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