Blue Bridge Java implementation to improve the algorithm Toto Cup pick apples

Questions apple-picking algorithm improves tata

Resource constraints
Time limit: 1.0s memory limit: 256.0MB
Problem Description
  Toto family's yard has an apple tree, every autumn tree will bear apples n. Apple ripe, Tao Tao will go apple-picking. Tao Tao has a 30 cm high bench, when she can not directly hand to pick apples and they will try again stepped on the bench.
  Now known n apples to the ground level, and Tao Tao handle straight time to reach the maximum height, Tao Tao please help her to count the number of apples to pick. Assuming that she met apples, apple will fall.
Input format
  input data consists of two lines. The first line includes only two positive integers n (5 <= n <= 200) and m (100 <= m <= 150), and the height represents the number of apples reach achievable Taotao (in centimeters). The second row contains an integer number n between 100 and 200 (including 100 and 200) (in centimeters), respectively separated by a space between the ground level to the integer apple, two adjacent.
Output format
  output comprises a line, which contains only an integer representing the number of Toto able to pick apples.
Sample input
10110

100,200,150,140,129 134,167,198,200,111
sample output
5

package 第二十一次模拟;

import java.util.Scanner;

public class 陶陶摘苹果 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int high=sc.nextInt()+30;
		int count=0;
		for (int i = 0; i <n; i++) {
			if(sc.nextInt()<=high){
				count++;
			}
		}
		System.out.println(count);
	}

}

Released 1588 original articles · won praise 20000 + · views 2.46 million +

Guess you like

Origin blog.csdn.net/a1439775520/article/details/105005605