饿了么笔试a多少道会挂呀
点赞 2

相关推荐

03-14 21:04
已编辑
北京邮电大学 Java
如题,楼主已经交卷,不存在作弊行为第二题,楼主的代码如下,测试了给出的用例2 3 4 答案正确,换成2 4 3答案错误,为什么?我不明白哪里有问题,求大伙帮忙看看由于明后天还有三场笔试,如果这个问题解决不了就三场全寄了,😭😭求求帮帮我自己试过自测用例2 4 3/1 3/2 4 4/ 1 4/2 3 3全都报错,但是单看自己的输出应该是对的,为什么ps:目前已知==2那里的if块输出应该是2 1 3,但是这和我上面提的用例无关吧,输入3 和4都不进到这个if的文本代码如下:import java.util.Scanner;// 注意类名必须为 Main, 不要有任何 package xxx 信息public class Main {    public static void main(String[] args) {        Scanner in = new Scanner(System.in);        // 注意 hasNext 和 hasNextLine 的区别        int t = in.nextInt();        for(int i = 0; i < t; i++){            int n = in.nextInt();            if (n < 4 ){                System.out.print(-1 + " ");            }else {                if (n*(n+1)*(2*n+1)/6 %3 == 0){                    for(int j = 1; j <= n; j++){                        System.out.print(j+" ");                    }                } else if (n*(n+1) *(2*n+1)/6 %3 == 1){                    System.out.print(2+" ");                    System.out.print(1+" ");                    for(int j = 3; j <= n; j++){                        System.out.print(j+" ");                    }                } else if (n*(n+1) *(2*n+1)/6 %3 == 2){                    System.out.print(1+" ");                    System.out.print(3+" ");                    System.out.print(2+" ");                    for(int j = 4; j <= n; j++){                        System.out.print(j+" ");                    }                }            }            System.out.println();        }    }}
ygLance:自测的时候?牛客的模式是除非你用题目给出的样例,否则不告诉你结果对不对的
投递饿了么等公司10个岗位
点赞 评论 收藏
分享
牛客网
牛客企业服务