杭电1.2.1 Biker's Trip Odometer(C++代码实现)

ACM学习之路(一阶)

杭电1.2.1 Biker’s Trip Odometer(C++实现)

因为本人才打算参加ACM竞赛,所以一切都得从头开始,现在我将我的解题代码放在CSDN上.一是为了激励自己,二是可能会给予一些初学者帮助.
题目描述:
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.
C++代码如下:

#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;
int main()
{
      float diameter;
      int num;
      float timeoftrip;
      float sum;
      int flag=0;
      const double p=3.1415927;
      while(cin>>diameter>>num>>timeoftrip){
      if(num==0)
        return 0;
        sum=num*diameter*p/5280/12;
        flag++;
       cout<<"Trip #"<<flag<<":"<<" "<<fixed<<setprecision(2)<<sum<<" "<<fixed<<setprecision(2)<<sum/(timeoftrip/3600)<<endl;
      }
        return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值