sicily 1051 小数的有效数字

1051. Biker‘s Trip Odomete

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

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).

Output

For each data set, print:

Trip #N: distance MPH

Of course N should be replaced by the data set number, distance by the total distance in miles (accurate to 2 decimal places) and MPH by the speed in miles per hour (accurate to 2 decimal places). Your program should not generate any output for the ending case when revolutions is 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.

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
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
	float diameter, revolution, time;
	int number = 1;
	while (cin >> diameter >> revolution >> time) {
		if (revolution == 0) {
			break;
		}
		float perimeter = 3.1415927 * ((diameter/12)/5280);
		float distance = revolution * perimeter;
		float mph = distance / (time/3600);         //小数有效数字
		cout << "Trip #" << number++ << ": "<< setprecision(2) << setiosflags(ios::fixed) << distance << " "<< mph << endl;

	}
	return 0;
}

  

时间: 2024-08-04 03:22:07

sicily 1051 小数的有效数字的相关文章

sicily 1051. Biker&#39;s Trip Odomete

DescriptionMost 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

Java保留小数点后有效数字

Java中的保留有效数字的方式有很多,感觉很是繁琐,不如直接: 1 System.out.printf("%.1f",69.66); 这是保留一位有效数字,自动四舍五入了,结果为69.7: : 你怎么了? : 我学不完了......o(╥﹏╥)o 学无止境啊... 如有个别回答错误,评论指出,我必更改,谢谢!?? 原文地址:https://www.cnblogs.com/Hrain/p/10360407.html

double型浮点数能精确到多少位小数?

问题2:double型浮点数能精确到多少位小数?或者,这个问题本身值得商榷? 既然double是浮点数,它的小数点的位置是“浮动”的,所以很难说double类型能精确到小数点后面几位.通常这个关于精度的问题都是通过它能表示的有效数字(十进制)的位数来表示的.遵循IEEE标准的8字节(64位)的double能表示的有效数字的位数是:15 ~ 16 测试一个: #include <stdio.h> int main(){ printf("%.20lf",1.0/3.0); }

oracle数据库基础

Oracle基础数据类型(4类): 字符型:字符串 char(最大2000), nchar(最大1000, 支持Unicode)--->固定长度,固定长度后即使不写满它自动也占这些位置 varchar2(最大4000), nvarchar2(最大2000, 支持Unicode)--->可变长度,只要不超出,输入多少占多少 数字类型 包括整数和小数 number(有效数字, 小数位数);   例:number(7,2) float()--->存储二进制类型的数据 日期类型:时间 date:

SQL 基础部分

Oracle基础数据类型: 4类: 字符型:字符串 char(最大2000), nchar(最大1000, 支持Unicode)--->固定长度 varchar2(最大4000), nvarchar2(最大2000, 支持Unicode)--->可变长度 数字类型 包括整数和小数 number(有效数字, 总位数); float()--->存储二进制类型的数据, 1-126位0.30103 日期类型:时间 date:取值范围:公元前4712年1月1号---公元9999年12月31号, 可

原生JS中对象相关API合集

Object对象 生成实例对象 var o = new Object() 属性 Object.prototype //返回原型对象 方法 Object.keys(o) //遍历对象的可枚举属性 Object.getOwnPropertyName(o) //遍历对象不可枚举的属性 对象实例的方法 valueOf // 返回当前对象对应的值. toString // 返回当前对象对应的字符串形式. toLocaleString // 返回当前对象对应的本地字符串形式. hasOwnProperty

JavaScript常用API

一.节点 1.1 节点属性 1.2 操作 1.3 Document节点 1.3.1 Document节点的属性 1.3.2 Document节点的方法 (1)读写方法 (2)查找节点 (3)生成节点 (4)事件方法 (5)其他 1.4 Element节点 1.4.1 Element节点的属性 (1)特性属性 (2)尺寸属性 (3)节点相关属性 1.4.2 Element节点的方法 (1)位置方法 (2)属性方法· (3)查找方法 Element.querySelector()   Element

Java中Double与BigDecimal的相互转换

今天写代码过程中,发现一个Double的变量通过new BigDecimal(Double d)转换为BigDecimal时,有效数字改变了,如下: public class BigDecimalTest { public static void main(String[] arg) { String s1 = "123.45"; Double d1 = new Double(s1); //使用String类型的形参构造BigDecimal BigDecimal bg1 = new B

web知识

来源:http://blog.csdn.net/wall1999/article/details/55100942 一.节点 1.1 节点属性 Node.nodeName //返回节点名称,只读 Node.nodeType //返回节点类型的常数值,只读 Node.nodeValue //返回Text或Comment节点的文本值,只读 Node.textContent //返回当前节点和它的所有后代节点的文本内容,可读写 Node.baseURI //返回当前网页的绝对路径 Node.owner