[NOIP2002 Popularization Group] Tao Tao picking apples

Topic link

Title Description
There is an apple tree in the yard of Tao Tao's house, and it will bear 10 apples every fall. 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 the height of 10 apples to the ground is known, and the maximum height 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 consists of 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), indicating the maximum height that the pottery can reach when the handle is straight.

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

Input and output sample
input

100 200 150 140 129 134 167 198 200 111
110

Output

5

Code:

#include<iostream>
using namespace std;
int num[10];
int main()
{
    
    
	int h, count = 0;
	for(int i = 0; i < 10; i++)
		cin >> num[i];
	cin >> h;
	for(int i = 0; i < 10; i++)
		if(num[i] <= h + 30) count++;
	cout << count << endl;
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_44826711/article/details/113725653