| ||||||||||
| 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 | |||||||||
WAWAWA!!谁能告诉我哪错了?#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator