1.格式,必须严格按照格式输出
2.当判断出输入的时间段中含有“-”不能停止输入,要将所有的数据都输入进来
3.样例中不包含小时,但是应该将小时也考虑进时间
4.对于最后求得秒要进行四舍五入,可以直接调用函数round.
具体的代码如下:
#include
#include
#include
#include
#include
#include
using namespace std;
int main(){
int num;
double dis;
string time;
int name;
int h1,m1,s1;
bool flag=false;
cin>>num>>dis;
string temp;
while(cin>>name){
int sumtime=0;
flag=false;
for(int i=0;i){
cin>>temp;
if(temp=="-:--:--"){
flag=true;
}
h1=temp[0]-'0';
m1=(temp[2]-'0')*10+(temp[3]-'0');
s1=(temp[5]-'0')*10+(temp[6]-'0');
sumtime=sumtime+h1*3600+m1*60+s1;
}
if(flag){
cout<endl;
}else{
int secPerKilo = round(sumtime/dis);
int minus = secPerKilo/60;
int secs = (int)(secPerKilo)%60;
cout<;
if(secs<10){
cout<<0;
}
cout<endl;
}
}
}