Problem 1164 Average is not Fast Enough!.
The meaning of problems
- Calculation of grade point average min / km (one thousand meters run how many minutes)
- Input:
Stage Number n (int 1 <= n < = 20), Total Distance d (double 0 <= d < = 200)
ranks number no, 1 race results, race results 2, ...... (h: mm: SS)
-: -: - represents the abandoned match
ended EOF - Output:
no (right justified 3): minutes: seconds (00) min / km
if people abandoned match
no (right justified 3): -
Thinking
Various input and output formats unfamiliar Kusi
- For each team:
one by one for each stage of the read results, if h = '-', skip the rest of the results, outputs '-'
otherwise accumulate h, m, s, all in terms of s, s / d s calculated / km, converted into a min / km
Code
#include<cstdio>
using namespace std;
int main(){
int n, no, m, s;
char h, temp[400];
double d, sum;
scanf("%d%lf", &n, &d);
while(scanf("%d", &no)!=EOF){
sum = 0;
for(int i=0; i<n; i++){
scanf(" %c", &h);
if(h=='-'){
gets(temp);
break;
}
scanf(":%d:%d", &m, &s);
sum += (h-'0')*3600;
sum += m*60;
sum += s;
}
if(h=='-')
printf("%3d: -\n", no);
else{
sum = sum/d;
m = sum/60;
s = (int)(sum - m*60 + 0.5);
if(s==60){
m++;
s = 0;
}
printf("%3d: %d:%02d min/km\n", no, m, s);
}
}
return 0;
}