Advertisement
metalni

APS Labs 3 Cik Cak Sekvenca

Nov 4th, 2020
1,273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3.  
  4. public class ZigZagSequence {
  5.  
  6.     static int najdiNajdolgaCikCak(int a[]) {
  7.         int counter = 1, max = 1;
  8.         for(int i=0; i<a.length-1; i++){
  9.             if((a[i]>0 && (a[i+1])<0) || (a[i]<0 && (a[i+1])>0))
  10.                 counter++;
  11.             else
  12.                 counter = 1;
  13.             if(counter > max)
  14.                 max = counter;
  15.         }
  16.         return max;
  17.     }
  18.  
  19.     public static void main(String[] args) throws Exception {
  20.         int i,j,k;
  21.  
  22.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  23.  
  24.         int N = Integer.parseInt(br.readLine());
  25.         int a[] = new int[N];
  26.         for (i=0;i<N;i++)
  27.             a[i] = Integer.parseInt(br.readLine());
  28.  
  29.         int rez = najdiNajdolgaCikCak(a);
  30.         System.out.println(rez);
  31.  
  32.         br.close();
  33.  
  34.     }
  35.  
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement