hdu acm steps Biker's Trip Odometer

题意:输入直径(英寸),转速(1/h),时间(秒),求一小时内的路程(英里)和 平均速度(mph = 英里/小时);

注意:单位转换,1英寸(in)= 1 / 12 / 5280 英里(mi),1 h = 3600 s ;

distance = P * diameter / 12 / 5280 * revolution;

speed = distence / ( time / 3600 ) = distence * 3600 / time;

源码如下:


#include<iostream>
#include<iomanip>
using namespace std;

int main(){
    int revolution,i = 0;
    double diameter,time;
    double distence,speed;
    // 常量必须为double值,数学中的π
    double const P = 3.1415927;
    while(cin>>diameter>>revolution>>time&&revolution){
        // 初始化数据
        distence = speed = 0;
        // 计算
        distence = P * diameter / 12 / 5280 * revolution;
        speed = distence * 3600 / time;
        cout<<"Trip #"<<++i<<": ";
        // 调用<iomanip>头文件中的设置精度的函数
        cout<<fixed<<setprecision(2);
        cout<<distence<<" "<<speed<<endl;
    }
    return 0;
}




Biker's Trip Odometer

自行车的里程表
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4287 Accepted Submission(s): 1904
 
Problem Description
Most bicycle speedometers work by using a Hall Effect sensor fastened to the front fork of the bicycle.
大多数自行车速度表的工作原理是通过使用霍尔效应传感器固定在自行车前叉。
 A magnet is attached to one of the spokes on the front wheel so that it will line up with the Hall Effect switch once per revolution of the wheel.
在前轮的辐条中,有一条加了一块磁铁,所以,车轮每旋转一次,霍尔效应开关就改变一次。
 The speedometer monitors the sensor to count wheel revolutions.
速度表监测传感器,传感器是计算车轮转速的工具,一般用的是霍尔效应开关。
 If the diameter of the wheel is known, the distance traveled can be easily be calculated if you know how many revolutions the wheel has made. 
假如已知车轮的直径,而且你也知道车轮的转速,那么旅行的长度就很容易计算。
In addition, if the time it takes to complete the revolutions is known, the average speed can also be calculated. 
此外,如果知道某时间内全部的转速,那么这段时间内的平均速度也就可以计算出来。
For this problem, you will write a program to determine the total distance traveled (in miles) and the average speed (in Miles Per Hour) 
对于这个题目,你的任务是计算路程和平均速度(单位:每一小时一英里),
given the wheel diameter, the number of revolutions and the total time of the trip. 
在已知车轮直径,转速,总时间的情况下。
You can assume that the front wheel never leaves the ground, and there is no slipping or skidding.
 你可以认为前轮不会离开地面,车子不会摔倒,地面不打滑等等一切都非常完美,不要想太多。
Input
Input consists of multiple datasets, one per line,
输入由多种数据集组成,每一组一行,
 of the form: diameter revolutions time
格式为: 直径  转速  时间
The diameter is expressed in inches as a floating point value. 
直径用浮点数保存,且单位是 英寸
The revolutions is an integer value. 
转速用整数保存,且单位是每 小时
The time is expressed in seconds as a floating point value. 
时间用浮点数保存,且单位是
Input ends when the value of revolutions is 0 (zero).
当输入转速的转速为0时,表示输入语句结束。
Output
For each data set, 
对于每一个输入集合,
print:                       Trip #N: distance MPH
输出格式如下: Trip #N: distance    MPH 
Of course N should be replaced by the data set number,
当然N应该由数据集编号代替;
 distance by the total distance in miles (accurate to 2 decimal places) 
distance应该由一英里的距离值代替(精确到两位小数),单位 英里
and MPH by the speed in miles per hour (accurate to 2 decimal places). 
MPH 应该由一英里每小时的速度值代替,单位是 没英里小时
Your program should not generate any output for the ending case when revolutions is 0.
当转速为0时,不要处理,这时程序结束。
Constants

For p use the value: 3.1415927.
There are 5280 feet in a mile.
There are 12 inches in a foot.
There are 60 minutes in an hour.
There are 60 seconds in a minute.
There are 201.168 meters in a furlong.

物理常数PI
p = 3.1415927
1)5280 英尺 = 1 英里
2)12 英寸 = 1 英尺
3)60 分钟 = 1 小时
4)60 秒 = 1 分钟
5)201.168 公尺 = 1 弗隆
6)1 mph = 1.609344 km/h
7)1英寸(in)=1 / ( 12 * 5280 )英里(mi)

 
Sample Input
26 1000 5
27.25 873234 3000
26 0 1000
 
Sample Output
Trip #1: 1.29 928.20
Trip #2: 1179.86 1415.84
 
 
Source
Greater New York 2003

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值