1007 of greedy strategy*

来源:互联网 发布:删除cadbak文件软件 编辑:程序博客网 时间:2024/05/20 13:41
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
 
题目要求:输入一些田径队名和成员的用时,输出队伍的平均速度。
题目思路:看懂题意后先转化为秒在进行计算后进行单位换算。并且按照输出格式输出。
细节:如何判断是否没有完成比赛,若有将其转化为int类的时间。定义距离要用double类,最后进行四舍五入。
ps:开始用了很多scanf发现无法正常运行,后来对scanf的理解更加深刻了,但仍然不是特别理解输入流中读取。
#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 ww[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(ww);                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
原创粉丝点击