water-Average is not Fast Enough
Average is not Fast Enough!
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 4 Accepted Submission(s) : 3
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
A relay is a race for two or more teams of runners. Each member of a team runs one section of the race. Your task is to help to evaluate the results of a relay race.
You have to process several teams. For each team you are given a list with the running times for every section of the race. You are to compute the average time per kilometer over the whole distance. That's easy, isn't it?
So if you like the fun and challenge competing at this contest, perhaps you like a relay race, too. Students from Ulm participated e.g. at the "SOLA" relay in Zurich, Switzerland. For more information visit http://www.sola.asvz.ethz.ch/ after the contest is over.
You have to process several teams. For each team you are given a list with the running times for every section of the race. You are to compute the average time per kilometer over the whole distance. That's easy, isn't it?
So if you like the fun and challenge competing at this contest, perhaps you like a relay race, too. Students from Ulm participated e.g. at the "SOLA" relay in Zurich, Switzerland. For more information visit http://www.sola.asvz.ethz.ch/ after the contest is over.
Input
The first line of the input specifies the number of sections n followed by the total distance of the relay d in kilometers. You may safely assume that 1 <= n <= 20 and 0.0 < d < 200.0. Every following line gives information about one team: the team number t (an integer, right-justified in a field of width 3) is followed by the n results for each section, separated by a single space. These running times are given in the format "h:mm:ss" with integer numbers for the hours, minutes and seconds, respectively. In the special case of a runner being disqualified, the running time will be denoted by "-:--:--". Finally, the data on every line is terminated by a newline character. Input is terminated by EOF.
Output
For each team output exactly one line giving the team's number t right aligned in a field of width 3, and the average time for this team rounded to whole seconds in the format "m:ss". If at least one of the team's runners has been disqualified, output "-" instead. Adhere to the sample output for the exact format of presentation.
Sample Input
2 12.5 5 0:23:21 0:25:01 42 0:23:32 -:--:-- 7 0:33:20 0:41:35
Sample Output
5: 3:52 min/km 42: - 7: 6:00 min/km
****************************************************************************************************************************************************
此题不难,注意下格式即可
View Code
1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 int main() 5 { 6 int n,t,h,m,s,flag,aver,sum; 7 float d; 8 scanf("%d%f",&n,&d); 9 while(scanf("%3d",&t)!=EOF) 10 { 11 flag=0; 12 sum=0; 13 for(int i=0;i<n;i++) 14 { 15 if(scanf("%d:%d:%d",&h,&m,&s)==3) 16 sum+=(h*3600+m*60+s); 17 else 18 { 19 scanf(":--:--"); 20 flag=1; 21 } 22 } 23 if(flag) 24 printf("%3d: -\n",t); 25 else 26 { 27 aver=sum/d+0.5; 28 m=aver/60; 29 s=aver%60; 30 printf("%3d: %d:%02d min/km\n",t,m,s); 31 } 32 } 33 return 0; 34 }
1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 int main() 5 { 6 int n,t,sum,aver,m,s; 7 float d; 8 char h,m1,m2,s1,s2; 9 scanf("%d%f",&n,&d); 10 while(scanf("%3d",&t)!=EOF) 11 { 12 bool flag=false; 13 sum=0; 14 for(int i=0;i<n;i++) 15 { 16 getchar(); 17 scanf("%c:%c%c:%c%c",&h,&m1,&m2,&s1,&s2); 18 if(h=='-') 19 flag=true; 20 sum+=((h-'0')*3600+(m1-'0')*600+(m2-'0')*60+(s1-'0')*10+(s2-'0')); 21 } 22 if(flag) 23 printf("%3d: -\n",t); 24 else{ 25 aver=sum/d+0.5; 26 m=aver/60; 27 s=aver%60; 28 printf("%3d: %d:%02d min/km\n",t,m,s); 29 } 30 31 } 32 return 0; 33 }
Do one thing , and do it well !