[c++]代码库
#include<iostream>
#include <math.h>
#include<string>
using namespace std;
int round(double a){
if(a - floor(a) >= 0.5){
a = (int)(a + 1);
}
return a;
}
int main(){
int n1, n2;//n2是队伍号码
string n4;//n4是时间
int total;
int flag;
double n3;
cin>>n1>>n3;//n1是接力人数,n3是公里数
while(cin>>n2){//处理每一队的数据
total = 0;
cout.width(3);
cout<<n2<<": ";
flag = 0;
for(int i = 0; i < n1; i++){
cin>>n4;
if(n4 != "-:--:--"){
total+=(int)(n4[6] - 48);
total+=((int)(n4[5] - 48)) * 10;
total+=((int)(n4[3] - 48)) * 60;
total+=((int)(n4[2] - 48)) * 600;
total+=((int)(n4[0] - 48)) * 3600;
}else{
flag = 1;
cout<<"-"<<endl;
if(i != n1 - 1){
string s1;
getline(cin, s1);
break;
}
}
}
if(flag == 1){
continue;
}
total = round(total / n3);
int t1, t2, t3, t4, t5;
t1 = total / 3600;
if(t1){
cout<<t1<<":";
total %= 3600;
}
t2 = total / 600;
if(t2){
cout<<t2;
total %= 600;
}else if(t1){
cout<<t2;
total %= 600;
}
t3 = total / 60;
cout<<t3;
if(t3){
total %= 60;
}
cout<<":";
t4 = total /10;
cout<<t4;
if(t4){
total %= 10;
}
t5 = total;
cout<<total;
cout<<" min/km"<<endl;
}
}