Created
June 12, 2019 16:39
-
-
Save DVegasa/0530616bd82f0467c331d098581f1b62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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