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

Re:WAWAWA!!谁能告诉我哪错了?

Posted by zyz at 2007-04-30 21:59:25 on Problem 2501
In Reply To:WAWAWA!!谁能告诉我哪错了? Posted by:zyz at 2007-04-30 21:48:38
> #include<iostream>
> #include<iomanip>
> using namespace std;
> 
> int main(){
>     char temp[30]={0};
>     double distance=0.0;
>     int lasttime=0;
>     double oldspeed=0.0;
>     double curspeed=0.0;
>     while(cin.getline(temp, sizeof(temp), '\n')){
>         char *space;
>         int hh, mm, ss;
>         for(int i=strlen(temp)-1;i>=0;i--)
>             if(temp[i]!=' ')
>                 break;
>             else
>                 temp[i]=0;
>         if(space=strchr(temp, ' ')){
>             *space=0;
>             sscanf(temp, "%d:%d:%d", &hh, &mm, &ss);space++;
>             temp[strlen(temp)]='\0';
> //            cout<<space<<endl;
>             if(sscanf(space, "%lf", &curspeed)==-1){
>                 curspeed=0.0;}
>   //          cout<<"*"<<curspeed<<endl;
>             distance = oldspeed*(hh*3600+mm*60+ss - lasttime)/3600;
原来是这里: += ...

>             lasttime = hh*3600+mm*60+ss;
>             oldspeed = curspeed;
> //            cout<<lasttime<<" "<<oldspeed<<endl;
>         }
>         else{
>             sscanf(temp, "%d:%d:%d", &hh, &mm, &ss);
>             int nowdis=0;
>             nowdis = (distance + oldspeed*(hh*3600+mm*60+ss - lasttime)/3600)*1000;
>             if(nowdis%10>=5){
>                 nowdis /= 10; nowdis += 1;}
>             else
>                 nowdis /= 10;
>             cout.width(2);
>             cout.fill('0');
>             cout<<hh<<":";
>             cout.width(2);
>             cout.fill('0');
>             cout<<mm<<":";
>             cout.width(2);
>             cout.fill('0');
>             cout<<ss<<" ";
>             cout.setf(ios::fixed);
>             cout.setf(ios::showpoint);
>             cout.precision(2);
>             cout<<(double)nowdis/100<<" km"<<endl;
>         }
>     }
> }

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