Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- public class ZigZagSequence {
- public static int checkNext(int broj){
- if(broj>0){
- return 1;
- }else if(broj<0){
- return -1;
- }else{
- return 0;
- }
- }
- static int najdiNajdolgaCikCak(int a[]) {
- // Vasiot kod tuka
- int max=0,counter=1;
- for(int i=0;i<a.length-1;i++) {
- if (checkNext(a[i]) == 1 && checkNext(a[i + 1]) == -1 ) {
- counter++;
- } else if (checkNext(a[i]) == -1 && checkNext(a[i + 1]) == 1) {
- counter++;
- } else {
- counter = 1;
- }
- if (counter > max) {
- max = counter;
- }
- }
- return max;
- }
- public static void main(String[] args) throws Exception {
- int i,j,k;
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- int N = Integer.parseInt(br.readLine());
- int a[] = new int[N];
- for (i=0; i<N; i++)
- a[i] = Integer.parseInt(br.readLine());
- int rez = najdiNajdolgaCikCak(a);
- System.out.println(rez);
- br.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement