Skip to content

Instantly share code, notes, and snippets.

@DVegasa
Created June 12, 2019 16:39
Show Gist options
  • Save DVegasa/0530616bd82f0467c331d098581f1b62 to your computer and use it in GitHub Desktop.
Save DVegasa/0530616bd82f0467c331d098581f1b62 to your computer and use it in GitHub Desktop.
package com.company;
import java.util.Scanner;
public class Main {
// 20 34 12 94 54 99 11 22
// ^------------^
//
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int prev = -1;
int maxH = 0;
int start = 0;
int count = 0;
int a;
while (true) {
a = sc.nextInt();
if (a == 0) break;
count++;
if (prev < 0) {
start = a;
}
if (a <= prev) {
int curH = prev - start;
if (curH > maxH) {
maxH = curH;
}
} else {
prev = a;
}
}
if (a <= prev) {
int curH = prev - start;
if (curH > maxH) {
maxH = curH;
}
} else {
prev = a;
}
if (maxH != 0) {
System.out.println("Получено чисел " + count);
System.out.println("Наибольшая высота подъёма " + maxH);
} else System.out.println(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment