任何人都可以指出我的错误在哪里。 一旦我在codechef上发布了它就会抛出NZEC错误。 任何人都知道为什么会出现非零退出代码错误。
import java.util.Scanner;
public class AlternatingSubarrayPrefix {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
for (int i = 0; i < t; i++) {
int n = scanner.nextInt();
int[] array = new int[n];
for (int k = 0; k < n; k++) {
array[k] = scanner.nextInt();
}
int count = 0;
int[] result = new int[n];
for (int j = 0; j < n-1 ; j++) {
if(array[j] < 0 && array[j+1] > 0 || array[j] > 0 && array[j+1] < 0)
result[j] = ++count;
else {
count = 1;
result[j] = count;
}
}
if(array[n-1] < 0 && array[n-2] > 0 || array[n-1] > 0 && array[n-2] < 0)
result[n-1] = ++count;
else {
count = 1;
result[n-1] = count;
}
for(int j = n-1; j >=0; j--)
System.out.print(result[j] + " ");
}
}
}