acm 1007 接力问题

来源:互联网 发布:马桶推荐 知乎 编辑:程序博客网 时间:2024/04/30 08:31

1.1007

2.

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[bk]12.5[bk][bk]5[bk]0:23:21[bk]0:25:01[bk]42[bk]0:23:32[bk]-:--:--[bk][bk]7[bk]0:33:20[bk]0:41:35

Sample Output
[bk][bk]5:[bk]3:52[bk]min/km[bk]42:[bk]-[bk][bk]7:[bk]6:00[bk]min/km

3.

计算各个接力队的平均速度。输入的第一个数N意思是比赛的节数,第二个数D 为赛道的距离,单位是千米。第二行第一个数是队伍编号,这个没有什么意义,照着输出就行了,后面是一个以h:mm:ss格式表示的时间,以空格分隔,意为这个队伍完成这一小节比赛所消耗的时间,把所有的时间加起来就是这个队跑完全程(也就是上面输入的D)所用的总时间。对于每一组输入数据,输出这个队伍的平均速度,单位是min/km(**参考异常网)

4.

1、输入编号的候用%3d,否则前面的空格就会把输入搞乱了

2、把h:mm:ss的时间当做字符串输入,放在一个char数组中,用 strtok把里面的数字分离

3、把单位换算成 m:ss,min/km,即跑一千米用多少时间

4、计算结果的过程中注意要四舍五入,不能全部用整形

5、输出结果时,注意当秒数只有1位数的时候要在前面补0(不能出现4:8这种格式)

5.

#include <cstdio>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<math.h>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<iomanip>
using namespace std;
int main()
{
    //freopen("r.txt", "r", stdin);
    int n,t,h,m,s,i,sum;
    char arr[100];
    double d;
    cin>>n>>d;
    while(~scanf("%d",&t))
    {
        int work=sum=0;
        for(i=0;i<n;i++)
        {
            if(scanf("%d:%d:%d",&h,&m,&s)==3)
            {
                sum+=h*3600+m*60+s;
            }
            else
            {
                gets(arr);
                work=1;
                break;
            }
        }
        if(work)
        {
            cout<<setw(3)<<t<<": -"<<endl;


        }
        else
        {
            sum=sum/d+0.5;


            cout<<setw(3)<<t<<": "<<sum/60<<":";
            if((sum%60)<10)
                cout<<0;
            cout<<sum%60<<" min/km"<<endl;
        }
    }


}

0 0
原创粉丝点击