AcWing Taotao Apple Picking

Title description:

There is an apple tree in the yard of Tao Tao’s house, and every fall it will bear 10 apples.

When the apples are ripe, Tao Tao will go to pick the apples.

Tao Tao has a 30 cm high bench. When she can't pick apples by hand, she will step on the bench and try again. 

Now that we know the height of 10 apples to the ground and the maximum height that Tao Tao can reach when her hand is straight, please help Tao Tao calculate the number of apples she can pick.

Suppose she touches an apple, the apple will fall.

Input format

The input file includes two lines of data.

The first line contains 10 integers (in centimeters) between 100 and 200 (including 100 and 200) to represent the height of 10 apples to the ground. Two adjacent integers are separated by a space.

The second line only contains an integer (in centimeters) between 100 and 120 (including 100 and 120), which represents the maximum height that the pottery can reach when the handle is straight.

Output format

The output file includes one line, this line only contains an integer, indicating the number of apples that Taotao can pick.

Input sample:

100 200 150 140 129 134 167 198 200 111
110

Sample output:

5
#include <iostream>
#include <cstdio>

using namespace std;
const int MAX = 15;

int a[MAX];
int height;

int main()
{
    for(int i = 0; i < 10; i++)
        scanf("%d", &a[i]);

    scanf("%d", &height);

    height += 30;

    int cnt = 0;
    for(int i = 0; i < 10; i++)
    {
        if(a[i] <= height)
            cnt++;
    }

    printf("%d\n", cnt);
    return 0;
}

 

Guess you like

Origin blog.csdn.net/weixin_44620183/article/details/113813734