Apple's solution to a problem Luo Gu Tao Tao Abstract P1046

  It is a very water topic.

  First, let's look at the topic :( probably describe) Tata family has an apple tree, autumn will bear 10 apples (only bear ten, so little thing),

These apples are highly, and Tao Tao also has a 30 cm bench. Let us ask this question Tao Tao arm length plus the bench thirty centimeters, can

How many apples picked to be.

  Ideas: a definition of a first array, the array is preferably larger, then the error array bounds prevented, then the definition of a O, represents the length of the arm Toto, defined sum,

Remember to be initialized to 0, because for a while to add up, so the beginning of the value must be 0. Then enter a loop array 10 are stored apples height, and

Enter o, i.e. the length of the arm Toto. Then the cycle again, and then determine: If the length of the arm plus the bench tata 30 cm greater than the height of apple,

So that Apple can be picked with a sum add up, and finally the output end.

· Code:

#include <the iostream> 
#include <cstdio> 
the using namespace STD; 
int main () { 
    int n-[110], sum = 0, O; // defines three variables, n array storing the apple height, sum stored 
// total how many apples can reach them, o storage Tao Tao handle straight time to reach the maximum height. 
    for (int i = 0; i <10; i ++) {// cycle 
        scanf ( "% d", & n [i]); // input apple height 
    } 
    Scanf ( "% D", & O); // Input Toto straight handle when the maximum height can be achieved 
    for (int i = 0; i <10; i ++) {// cycle 
        if (n [i] <= o + 30) {// If the height is less than the number of apples Toto hand stretched to reach the maximum height // add height stepping on the bench, then Apple will be able to be picked. 
            sum ++; // use the sum added up} 
    } 
    the printf ( "% D", sum); // number of outputs can be picked apples in 
    return 0; // End 
}

  I think this method should be regarded as a relatively simple.

 

Guess you like

Origin www.cnblogs.com/murongxueqing/p/11183219.html