题解 | #求小球落地5次后所经历的路程和第5次反弹的高度#
求小球落地5次后所经历的路程和第5次反弹的高度
https://www.nowcoder.com/practice/2f6f9339d151410583459847ecc98446
#include <iostream>
using namespace std;
int main() {
float hight;
cin >> hight;
float s = 0;
for(int i = 0;i < 5;i++){
s =s+ hight + hight/2;
hight = hight/2;
}
cout << s - hight<< endl;
cout << hight << endl;
}
// 64 位输出请用 printf("%lld")
不知道为啥是中等题。
用个float解决小数问题就完事了
华为机试刷题记录 文章被收录于专栏
记录一下手打代码的解题思路方便复习
