zoukankan      html  css  js  c++  java
  • (周日赛) Average is not Fast Enough!

    题意:求平均每千米花的时间,注意精度和格式

    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'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

     1 #include<stdio.h>
     2 #include<string.h>
     3 int main()
     4 {
     5     int n,num,i,sum; 
     6     double l;
     7     scanf("%d %lf",&n,&l);
     8     while(~scanf("%d",&num))
     9     {
    10         int flag=1;
    11         char a[100];
    12         int h=0,m=0,s=0;
    13         for(i=0;i<n;i++)
    14         {
    15             scanf("%s",a);
    16             if(flag)
    17             {
    18                 if(a[0]=='-')
    19                     flag=0;
    20                 else
    21                 {
    22                     h+=a[0]-'0';
    23                     m+=(a[2]-'0')*10+a[3]-'0';
    24                     s+=(a[5]-'0')*10+a[6]-'0';
    25                     sum=h*3600+m*60+s;
    26                 }
    27             }
    28         }
    29         printf("%3d: ",num);
    30         if(flag==0)
    31             printf("-
    ");
    32         else
    33         {
    34             sum=sum/l+0.5; 
    35             int minute=sum/60;
    36             int second=sum%60;
    37             printf("%d:",minute);
    38             if(second<10)
    39             printf("0");
    40             printf("%d min/km
    ",second);
    41         }
    42     }
    43     return 0;
    44 }
    45             
  • 相关阅读:
    Java Json 数据下划线与驼峰格式进行相互转换
    php 将数组转换网址URL参数
    Swagger2常用注解及其说明 (转)
    Java中 VO、 PO、DO、DTO、 BO、 QO、DAO、POJO的概念(转)
    bootstrap.css.map 404
    Git发生SSL certificate problem: certificate ha错误的解决方法
    防火墙禁ping:虚拟机ping不通主机,但主机可以ping虚拟机
    PhpStorm本地断点调试
    Java语言中姐种遍历List的方法总结
    Ubuntu18.04安装mysql5.7
  • 原文地址:https://www.cnblogs.com/awsent/p/4280467.html
Copyright © 2011-2022 走看看