Topic link: Average is not Fast Enough!
1 #include <iostream> 2 #include <cstring> 3 #include <string> 4 #include <cstdio> 5 using namespace std; 6 int main() 7 { 8 int n, id; 9 double d; 10 cin>>n>>d; 11 while (cin>>id) { 12 printf("%3d: ", id); 13 int mark = 0; 14 int time = 0 ; 15 for ( int i= 0 ; i<n; i++ ) { 16 string str; 17 cin>> str; 18 if (str[ 0 ] == ' - ' ) { 19 mark = 1 ; 20 // printf ("-\n"); can't be output here, because there will be multiple failures, WA several times 21 } 22 if (mark== 1 ) continue ; 23 time += (str[ 0 ]- '0') * 3600+ ((str[2]-'0')*10+(str[3]-'0')) * 60 + (str[5]-'0')*10+(str[6]-'0'); 24 } 25 if (mark == 1) { 26 printf("-\n"); 27 continue; 28 } 29 double a = time / d; 30 int t = (int)(a + 0.5); 31 printf("%d:%02d min/km\n", t/60, t%60); 32 } 33 return 0; 34 }