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 |
这是我的调试程序,有空的帮我看一看,第一行没有速度我考虑了,24点到0点我也考虑了,怎么还会错?????#include <iostream> #include <string> #include <fstream> using namespace std; double second(string s) { double time=0; time+=((s[0]-'0')*10+s[1]-'0')*3600; time+=((s[3]-'0')*10+s[4]-'0')*60; time+=(s[6]-'0')*10+s[7]-'0'; return time; } int main() { fstream inf; inf.open("abc.txt",ios::in); string s; char c; double speed; double time; double dis; double temp; int flag=0; while(inf>>s && inf.get(c)) { if(c==' ')break; } inf>>speed; time=second(s); dis=0; while(inf>>s) { inf.get(c); temp=second(s); if(flag==3600) temp+=flag; else if(temp<time) { flag=3600; temp+=flag; } dis+=(temp-time)*speed/3600; time=temp; if(c==' ') { inf>>speed; } else { cout<<s<<' '; printf("%.2f km\n",dis); } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator