摘桃子

//2017年8月21日19:58:31 
//刚才做模拟题 没来得及粘贴答案,哎。
//题目大概要求 起初没看懂啥意思。 
//猴子从 桃子数目不同桃树数组里摘桃子,每棵树只能摘一个,不回头,并且要摘的下一个桃树的桃子数目比刚摘桃树上的要多。

  

package ali;

import java.util.*;

public class Main {
	static int pick(int[] peaches) {
		int max = 0;
		for (int i = 0; i < peaches.length - 1; i++) {
			
			int res = 1;
			int now = peaches[i];
			// 1.寻找比当前数字大的数字 改数目+1且更改now
			for (int j = i + 1; j < peaches.length; j++) {
				if (peaches[j] > now) {
					res++;
					now = peaches[j];
				}
			}
			// 2.是否桃子最多?多则改
			max = res > max ? res : max;
		}

		return max;
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int trees = Integer.parseInt(in.nextLine().trim());
		int[] peaches = new int[trees];
		for (int i = 0; i < peaches.length; i++) {
			peaches[i] = Integer.parseInt(in.nextLine().trim());
		}

		System.out.println(pick(peaches));
	}
}


输入

  5
  10
  4
  5
  12
  8

  输出
  3

原文地址:https://www.cnblogs.com/startnow/p/7406373.html