Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. package com.telerikacademy;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6.  
  7. public class LongestIncreasingSequence {
  8.  
  9.     public static void main(String[] args) throws IOException {
  10.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  11.         short num = Short.parseShort(br.readLine());
  12.         short[] arr = new short[num];
  13.  
  14.         maximalIncreasingSequence(br, num, arr);
  15.     }
  16.  
  17.     private static void maximalIncreasingSequence(BufferedReader br, short num, short[] arr) throws IOException {
  18.         short maxSubStrLength = 1;
  19.         short tempMaxLength = 1;
  20.         arr[0] = Short.parseShort(br.readLine());
  21.         for (short i = 1; i < num; i++) {
  22.             arr[i] = Short.parseShort(br.readLine());
  23.             if (arr[i - 1] < arr[i]) {
  24.                 ++tempMaxLength;
  25.             } else if (tempMaxLength > maxSubStrLength) {
  26.                 maxSubStrLength = tempMaxLength;
  27.                 tempMaxLength = 1;
  28.             }
  29.         }
  30.         if (tempMaxLength > maxSubStrLength) {
  31.             maxSubStrLength = tempMaxLength;
  32.         }
  33.  
  34.         System.out.println(maxSubStrLength);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement