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.
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
- 1007 of greedy strategy*
- 1000 of greedy strategy*
- 1001 of greedy strategy
- 1002 of greedy strategy
- 1003 of greedy strategy
- 1004 of greedy strategy
- 1005 of greedy strategy
- 1010 of greedy strategy
- 1011 of greedy strategy
- 1012 of greedy strategy
- 1013 of greedy strategy
- 1014 of greedy strategy
- 1015 of greedy strategy
- 1016 of greedy strategy
- 1017 of greedy strategy*
- the summary of greedy strategy
- Change of strategy
- 1006 of strategy
- MATLAB/c++混合编程
- wget完成ftp链接下载
- finalize()方法什么时候被调用?析构函数(finalization)的目的是什么?
- hdu4496 并查集
- 点击文本可选中选择框
- 1007 of greedy strategy*
- java--自定义标签(tag、tld两种)
- mybatis第2天
- POJ 3678 Katu Puzzle 2-SAT
- JVM(一)--概述
- 按订单号(String常量池唯一,即对象唯一)加同步锁
- leetcode: Next Permutation
- 我的Python学习之路之基本语法-输入输出
- Python2.6和Python3.0中对除法操作的异同