fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class PlusMinus {
  6. public static void main (String[] args) throws java.lang.Exception {
  7. Scanner read = new Scanner(System.in);
  8. int m = read.nextInt();
  9. int Z[] = new int [m];
  10. int count = 0;
  11. int sign = 0;
  12.  
  13. for (int i = 0; i < m; i++){
  14. Z[i] = read.nextInt();
  15. }
  16.  
  17. int i = 0;
  18. for(i = 0; (Z[i] == 0) && (i < m); i++ );
  19. sign = Z[i];
  20.  
  21. for (int j = 0; j < m; j++) {
  22. if (sign * Z[j] < 0) {
  23. sign = Z[j];
  24. count ++;
  25. }
  26. }
  27. System.out.print("Число чередований знака = "+count);
  28. }
  29. }
Success #stdin #stdout 0.14s 321280KB
stdin
11
0 -2 0 -10 2 -1 0 0 3 2 -3
13
0 0 0  -2 0 -10 2 -1 0 0 3 2 3

stdout
Число чередований знака = 4