Advertisement
Guest User

1.2 (2)

a guest
Sep 16th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. public class ScenaSequence {
  2.  
  3.     static class NumSubSequence {
  4.         int beginIdex;
  5.         int endIdex;
  6.         int lengthSeq = 2;
  7.  
  8.         NumSubSequence(int beginIdex) {
  9.             this.beginIdex = beginIdex;
  10.         }
  11.  
  12.         NumSubSequence(int beginIdex, int lengthSeq) {
  13.             this.beginIdex = beginIdex;
  14.             this.lengthSeq = lengthSeq;
  15.         }
  16.  
  17.         void riseLength() {
  18.             lengthSeq++;
  19.             endIdex = beginIdex + lengthSeq - 1;
  20.         }
  21.  
  22.         @Override
  23.         public String toString() {
  24.             return "NumSubSequence{" +
  25.                     "beginIdex=" + beginIdex +
  26.                     ", endIdex=" + endIdex +
  27.                     ", lengthSeq=" + lengthSeq +
  28.                     '}';
  29.         }
  30.     }
  31.  
  32.     public static void main(String[] args) {
  33.         NumSubSequence tmpSeq = null;
  34.         NumSubSequence bigestSeq = new NumSubSequence(0, 0);
  35.         int [] sequence = {1, 2, 3, 4, 2, 3, 4, 5, 6, 7, 8, 1};
  36.         for (int i = 0; i < sequence.length - 1; i++) {
  37.             if (sequence[i] < sequence[i + 1]) {
  38.                 if (tmpSeq == null)
  39.                     tmpSeq = new NumSubSequence(i);
  40.                 else tmpSeq.riseLength();
  41.                 if (bigestSeq.lengthSeq < tmpSeq.lengthSeq) bigestSeq = tmpSeq;
  42.             } else tmpSeq = null;
  43.         }
  44.         System.out.println(bigestSeq);
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement