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 |
whats Wrong ??#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator