8月8日,网易互娱android客户端笔试代码

1.单词词频(100%):
    public static int countWordFrequence() {
        Scanner in = new Scanner(System.in);
        HashMap<String, Integer> wordMap = new HashMap<>();
        int num = Integer.parseInt(in.nextLine());
        String input = null;
        for (int i = 0; i < num; i++) {
            input = in.nextLine();
            Integer count = wordMap.get(input);
            if (count == null)
                wordMap.put(input, 1);
            else
                wordMap.put(input, count + 1);
        }
        int count = 0;
        for (Integer wordCount : wordMap.values()) {
            double frequence = ((double) wordCount) / num;
            if (frequence >= 0.01)
                count++;
        }
        return count;
    }
2.E,EM,M,EH,H(0%)(自测用例都过了,但是最后提交0%):
    public static int testCount() {
        Scanner in = new Scanner(System.in);
        int[] testCount = new int[5];
        for (int i = 0; i < 5; i++) {
            testCount[i] = in.nextInt();
        }

        int sum = 0;
        for (int i = 0; i < testCount.length; i++) {
            int x, y, z;
            for (x = 0; x < 2; x++) {
                if (testCount[x] > 0)
                    break;
            }

            for (y = 1; y < 4; y++) {
                if (x != y && testCount[y] > 0) {
                    break;
                }
            }

            for (z = 3; z < 5; z++) {
                if (z != y && testCount[z] > 0) {
                    break;
                }
            }
            if (minus(testCount, x, y, z >= 5 ? 4 : z))
                sum++;
        }
        return sum;
    }

    private static boolean minus(int[] testCount, int x, int y, int z) {
        if (testCount[x] <= 0) {
            return false;
        }
        testCount[x]--;
        if (testCount[y] <= 0) {
            return false;
        }
        testCount[y]--;

        if (testCount[z] <= 0) {
            return false;
        }
        testCount[z]--;
        return true;
    }



3.铺地毯(0%):动态规划,但是没找到递推公式,这道题没写好,最后实在没办法开始猜答案了
    private static final int[] floor = new int[]{1, 3};

    public static int countFloorTimes(int n) {
        int[] countTimes = new int[n + 1];
        countTimes[0] = 1;
        for (int floorNum : floor) {
            for (int j = floorNum; j <= n; j++) {
                countTimes[j] = (countTimes[j] + countTimes[j - floorNum]) % 10007;
            }
        }
        return (n > 3 ? (countTimes[n] * 2 * 3 + 1) : (countTimes[n] * 2)) % 10007;
    }

4.想用邻接矩阵做,但是想不起来思路了,写了一半放弃了:
    static class Direction implements Comparable<Direction> {
        int from;
        int to;

        public Direction(int from, int to) {
            this.from = from;
            this.to = to;
        } @Override public int compareTo(Direction o) {
            return to - o.to;
        }
    }

    public static int countProfesserTime() {
        int sum = 0;

        int[][] map;
        Scanner in = new Scanner(System.in);
        Direction[] directions;
        int num, count;
        num = in.nextInt();
        count = in.nextInt();
        map = new int[num + 1][num + 1];
        directions = new Direction[count];
        for (int i = 0; i < count; i++) {
            int x = in.nextInt();
            int y = in.nextInt();
            directions[i] = new Direction(x, y);
        }

        Arrays.sort(directions);
        for (Direction direction : directions) {
            map[direction.from][direction.to] = 1;
        }

    }

    public boolean findPath(int[][] map, Direction direction) {
        int start = direction.from;
        int end = direction.to;
        while (true) {

        }
    }

每道题都写了,但是只AC了第一道,凉凉预定

#笔试题目#
全部评论
最后结果怎么样?
点赞 回复 分享
发布于 2020-09-25 22:21

相关推荐

05-12 17:00
门头沟学院 Java
king122:你的项目描述至少要分点呀,要实习的话,你的描述可以使用什么技术,实现了什么难点,达成了哪些数字指标,这个数字指标尽量是真实的,这样面试应该会多很多,就这样自己包装一下,包装不好可以找我,我有几个大厂最近做过的实习项目也可以包装一下
点赞 评论 收藏
分享
求面试求offer啊啊啊啊:这个在牛客不是老熟人了吗
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务