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.
 
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
 
 #include <stdio.h>
#include <string.h> char s[][];
int time[]; int main()
{
int N,n;
double d;
int num,i,j;
double res1;
int res2;
scanf("%d",&N);
scanf("%lf",&d);
memset(s,,sizeof(s));
while(scanf("%3d",&num)!=EOF)
{
int t=,totle=,k=;
//char h,m1,m2,s1,s2;
for(i=;i<N;i++)
{
getchar();
scanf("%s",s[i]);
//printf("%s\n",s[i]);
//scanf("%c:%c%c:%c%c",&h,&m1,&m2,&s1,&s2);
t=(s[i][]-'')*+(s[i][]-'')*+(s[i][]-'')*+(s[i][]-'')*+s[i][]-'';
//t=(h-'0')*3600+((m1-'0')*10+(m2-'0'))*60+(s1-'0')*10+(s2-'0');
if(t>)
{
totle+=t;
}
else
{
k=;
continue;
}
}
if(k==)
{
printf("%3d: -\n",num);
}
else
{
res2 = (int)totle*1.0/(d*);
res1 = (totle*1.0/(d*) - res2)*;
if(res1>=59.5)
{res2+=;res1=;}
printf("%3d:%2d:%02.0lf min/km\n",num,res2,res1);
}
}
//while(1);
return ;
}

网上不错的解法:

 #include<stdio.h>
int main()
{
int n;
double d;
int num;
char h,m1,m2,s1,s2;
scanf("%d",&n);
scanf("%lf",&d);
while(scanf("%d",&num)!=EOF)
{ printf("%3d: ",num);
bool flag=true;
int sumtime=;
for(int i=;i<n;i++)
{getchar();
scanf("%c:%c%c:%c%c",&h,&m1,&m2,&s1,&s2);
if(h=='-') flag=false;
if(flag==false)continue;
sumtime+=(h-'')*+((m1-'')*+(m2-''))*+(s1-'')*+(s2-'');
}
if(flag==false)printf("-\n");
else
{
double t1=sumtime/d;
int t2=(int)(t1+0.5);
printf("%d:%02d min/km\n",t2/,t2%); }
}
return ;
}

总结:题比较简单,需认真读题弄明白题意,注意输入的格式

最新文章

  1. Andriod学习笔记3:Mac 平台下搭建 CLion 集成开发环境
  2. 转:C++ Boost/tr1 Regex(正则表达式)快速指南
  3. http请求利器: 今天配置出了RESTClient,用MAVEN构建了UI运行包
  4. PHP 中安装memcache扩展文件下载对应地址。
  5. 关于sphinx+PHP在高并发时响应性能低下的解决办法
  6. JDBC资料集
  7. [POJ] #1001# Exponentiation : 大数乘法
  8. c# 远程监控(1) 大纲
  9. Spring redirect直接返回项目根文件夹
  10. [LeetCode]题解(python):136-Single Number
  11. VS EF Error: Configuration Error extension=&quot;.edmx&quot; type=&quot;System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider&quot;
  12. poj3006 筛选法求素数模板(数论)
  13. 测试开发Python培训:抓取新浪微博抓取数据-技术篇
  14. python_web框架
  15. 调整登录会话和资源限制,bash和csh的ulimit设置方法
  16. java List递归排序,传统方式和java8 Stream优化递归,无序的列表按照父级关系进行排序(两种排序类型)
  17. java断言assert初步使用:断言开启、断言使用
  18. Ckeditor失去焦点前保留光标位置
  19. Best practices for Express app structure
  20. Kafka消息系统

热门文章

  1. E20171006-hm
  2. [Swift通天遁地]四、网络和线程-(1)线程的锁和解锁
  3. CyclibcBarrier与CountDownLatch区别
  4. 【BZOJ2149】拆迁队(斜率优化DP+CDQ分治)
  5. 查看当前linux版本
  6. SVN系列学习(二)-小乌龟的安装与配置
  7. MVC系列学习(二)-初步了解ORM框架-EF
  8. (转)Vue 爬坑之路(三)—— 使用 vue-router 跳转页面
  9. xampp中localhost与DreamWaver站点设置问题
  10. fastjson——json工具库