HUAWEI OD machine test - Find the distance traveled by the ball after it hits the ground 5 times and the height of the 5th rebound (C++ & Java & JS & Python)

describe

Assume that a ball falls freely from any height, and bounces back to half of its original height each time it hits the ground; after falling again, how many meters did it travel when it hit the ground for the fifth time? How high is the fifth rebound?

Data range: The initial height of the input ball satisfies 1≤�≤1000 1≤n≤1000 and is guaranteed to be an integer

Enter a description:

Input the starting height, int type

Output description:

Output the total number of meters and the height of the fifth rebound when it landed for the fifth time.
Note: You can think that you can pass this question if you output the result with six or more decimal places.

Example 1

enter:

1

output:

2.875
0.03125

Java:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String s;
        while((s = bf.readLine()) != null){//多组输入
            double h = Double.parseDouble(s);//记录总的
            double temp = h/2;//弹跳多高
            for(int i=1;i<5;i++){
                h +&#

Guess you like

Origin blog.csdn.net/m0_68036862/article/details/132716876