In Tao-Tao's backyard, there is an apple tree that bears 10 apples every autumn. When the apples are ripe, Tao-Tao goes to pick them. Tao-Tao has a 30-centimeter-high stool. When she can't reach the apples directly with her hands, she stands on the stool to try again.
Now that we know the height of the 10 apples above the ground and the maximum height Tao-Tao can reach with her hands extended, let's calculate the number of apples she can pick. Assuming that when she touches an apple, it falls down.
Sample Inputs/Outputs
Sample Input(s) | Sample Output(s) |
---|---|
Each input consists of two lines of data. The first line contains 10 integers between 100 and 200 (in centimeters), representing the height of the 10 apples above the ground. The second line contains an integer between 100 and 120 (in centimeters), indicating the maximum height Tao-Tao can reach with her hands extended. | For each set of input, output an integer representing the number of apples Tao-Tao can pick. |
100 200 150 140 129 134 167 198 200 111 110 | 5 |
Thought Process
Because there's a 30-centimeter-long stool, you can subtract 30 centimeters from the input apple heights. Then, you can simply check if each height is less than or equal to the maximum height Tao-Tao's hand can reach.
Sample Code-ZeroJudge B138: Picking Apples
#include <iostream>
#include <vector>
using namespace std;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
vector<int>num;
for (int i = 0; i<10; i++)
{
int tmp;
cin >> tmp;
tmp -= 30;
num.push_back(tmp);
}
int height, ans = 0;
cin >> height;
for (int i = 0; i<10; i++)
{
if (height >= num[i]) ans++;
}
cout << ans << "\n";
}
//ZeroJudge B138
//Dr. SeanXD