hdu_1036_Average is not Fast Enough_201311021335
Average is not Fast Enough!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3436 Accepted Submission(s): 1348
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
Source
Recommend
1 #include <stdio.h> 2 #include <string.h> 3 4 char s[22][10]; 5 int time[22]; 6 7 int main() 8 { 9 int N,n; 10 double d; 11 int num,i,j; 12 double res1; 13 int res2; 14 scanf("%d",&N); 15 scanf("%lf",&d); 16 memset(s,0,sizeof(s)); 17 while(scanf("%3d",&num)!=EOF) 18 { 19 int t=0,totle=0,k=1; 20 //char h,m1,m2,s1,s2; 21 for(i=0;i<N;i++) 22 { 23 getchar(); 24 scanf("%s",s[i]); 25 //printf("%s\n",s[i]); 26 //scanf("%c:%c%c:%c%c",&h,&m1,&m2,&s1,&s2); 27 t=(s[i][0]-'0')*3600+(s[i][2]-'0')*600+(s[i][3]-'0')*60+(s[i][5]-'0')*10+s[i][6]-'0'; 28 //t=(h-'0')*3600+((m1-'0')*10+(m2-'0'))*60+(s1-'0')*10+(s2-'0'); 29 if(t>0) 30 { 31 totle+=t; 32 } 33 else 34 { 35 k=0; 36 continue; 37 } 38 } 39 if(k==0) 40 { 41 printf("%3d: -\n",num); 42 } 43 else 44 { 45 res2 = (int)totle*1.0/(d*60); 46 res1 = (totle*1.0/(d*60) - res2)*60; 47 if(res1>=59.5) 48 {res2+=1;res1=0;} 49 printf("%3d:%2d:%02.0lf min/km\n",num,res2,res1); 50 } 51 } 52 //while(1); 53 return 0; 54 }
网上不错的解法:
1 #include<stdio.h> 2 int main() 3 { 4 int n; 5 double d; 6 int num; 7 char h,m1,m2,s1,s2; 8 scanf("%d",&n); 9 scanf("%lf",&d); 10 while(scanf("%d",&num)!=EOF) 11 { 12 13 printf("%3d: ",num); 14 bool flag=true; 15 int sumtime=0; 16 for(int i=0;i<n;i++) 17 {getchar(); 18 scanf("%c:%c%c:%c%c",&h,&m1,&m2,&s1,&s2); 19 if(h=='-') flag=false; 20 if(flag==false)continue; 21 sumtime+=(h-'0')*3600+((m1-'0')*10+(m2-'0'))*60+(s1-'0')*10+(s2-'0'); 22 } 23 if(flag==false)printf("-\n"); 24 else 25 { 26 double t1=sumtime/d; 27 int t2=(int)(t1+0.5); 28 printf("%d:%02d min/km\n",t2/60,t2%60); 29 30 } 31 } 32 return 0; 33 }
总结:题比较简单,需认真读题弄明白题意,注意输入的格式