我正在尝试解决似乎是一个相对简单的问题,输入孩子的数量和糖果的总数,如果糖果可以在孩子之间平均分配,则打印“是”,否则打印“否” .
从图中可以看出,前两个测试用例通过了,而最后一个没有通过。我在这里挠头,有什么想法吗?
import java.util.*;
public class AnotherCandies {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int cases = sc.nextInt();
for(int i = 0; i < cases; i++)
{
long numKids = sc.nextLong();
long total = 0;
for(int j = 0; j < numKids; j++)
{
long n = sc.nextLong();
total += n;
}
if(total % numKids == 0)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
慕哥9229398
慕运维8079593
相关分类