可以帮我看一下我第一题的代码问题在哪吗,我卡在16.67不动了 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 int n = in.nextInt(); int mat[] = new int[n]; for(int i = 0;i < n;i++){ mat[i] = in.nextInt(); } if(n <= 2) System.out.print(0); else{ int ans = 0; int ou = 0; int ji = 0; for(int i = 2;i < n;i++){ if(mat[i-2] % 2 == 0) ou++; else if(mat[i-2] % 2 == 1) ji++; if(mat[i] % 2 == 0) ans += ou; else if(mat[i] % 2 == 1) ans += ji; } System.out.print(ans); } } }
点赞 1

相关推荐

牛客网
牛客企业服务