我在"Codeforces"问题中找不到我的错误



问题是- https://codeforces.com/problemset/problem/231/A我很确定我在Java中找到了正确的解决方案,当我尝试它时,它工作正常,但当我提交它时,它在测试1中显示错误。如果有人能指出这个错误就太有帮助了。我的代码在下面:

import java.util.*;
public class A_Team {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Number of Question: ");
int count = 0;
int loop = sc.nextInt();
for (int i = 0; i < loop; i++) {
int arr[] = new int[3];
for (int j = 0; j < 3; j++) {
arr[j] = sc.nextInt();
}
if(arr[0] + arr[1] + arr[2] >= 2){
count = count + 1;
}
}
System.out.println(count);
}
}

注意:请不要要求更改语言,我是编程新手,只懂一点C和Java。

通常这些代码挑战不希望您输出答案以外的任何内容。它们通常由自动软件判断或评分,该软件以精确的格式寻找答案。删除System.out.println("Enter Number of Question: ");

  1. n或者在你的例子中循环应该是1≤n≤1000所以检查

  2. forj循环具有与数组循环相同的长度,因此您可以在上面声明常量或使用数组长度。因此,如果需要的话,您不必更改两次。

  3. 如果你需要像sum(Arrays.stream(arr).sum())这样的数组方法,可以使用Arrays类。

    public class A_Team {
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter Number of Question: ");
    int count = 0;
    int loop = sc.nextInt();
    //1.
    if (1 <= loop && loop <= 1000) {
    for (int i = 0; i < loop; i++) {
    int[] arr = new int[3];
    //2.
    for (int j = 0; j < arr.length; j++) {
    arr[j] = sc.nextInt();
    }
    //3.
    int sum = Arrays.stream(arr).sum();
    if (sum >= 2) {
    count += 1;
    }
    }
    }
    System.out.println(count);
    }
    }
    

相关内容

最新更新