Advertisement
BorjanCrvenkov

Aips lab3 Cik Cak sekvenca

Nov 7th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3.  
  4. public class ZigZagSequence {
  5.  
  6.  
  7. public static int checkNext(int broj){
  8. if(broj>0){
  9. return 1;
  10. }else if(broj<0){
  11. return -1;
  12. }else{
  13. return 0;
  14. }
  15. }
  16.  
  17. static int najdiNajdolgaCikCak(int a[]) {
  18. // Vasiot kod tuka
  19. int max=0,counter=1;
  20. for(int i=0;i<a.length-1;i++) {
  21.  
  22. if (checkNext(a[i]) == 1 && checkNext(a[i + 1]) == -1 ) {
  23. counter++;
  24.  
  25. } else if (checkNext(a[i]) == -1 && checkNext(a[i + 1]) == 1) {
  26. counter++;
  27.  
  28. } else {
  29. counter = 1;
  30. }
  31. if (counter > max) {
  32. max = counter;
  33. }
  34.  
  35. }
  36. return max;
  37. }
  38.  
  39. public static void main(String[] args) throws Exception {
  40. int i,j,k;
  41.  
  42. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  43.  
  44. int N = Integer.parseInt(br.readLine());
  45. int a[] = new int[N];
  46. for (i=0; i<N; i++)
  47. a[i] = Integer.parseInt(br.readLine());
  48.  
  49. int rez = najdiNajdolgaCikCak(a);
  50. System.out.println(rez);
  51.  
  52. br.close();
  53.  
  54. }
  55.  
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement