8月24日中兴笔试-AK代码

题目难度不大,输入输出很恶心

为了部落

模版题:经典求最短路径 Dijkstra

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        while (input.hasNextLine()){
            String line = input.nextLine();
            String[] arr = line.substring(1, line.length() - 1).split(",");

            int n = Integer.parseInt(input.nextLine());
            int k = Integer.parseInt(input.nextLine()) - 1;

            List<int[]>[] adj = new List[n];
            for(int i = 0; i < n; ++i) adj[i] = new ArrayList<>();

            for(int i = 0; i < arr.length; i += 3){
                int from = Integer.parseInt(arr[i].substring(1)) - 1, to = Integer.parseInt(arr[i + 1]) - 1, cost = Integer.parseInt(arr[i + 2].substring(0, arr[i + 2].length() - 1));
                adj[from].add(new int[]{to, cost});
            }

            int[] ans = getDistince(k, adj, n);
            int res = 0;
            for(int num : ans) res = Math.max(num, res);
            System.out.println(res == Integer.MAX_VALUE / 2 ? -1 : res);
        }
    }
    static int[] getDistince(int start, List<int[]>[] adj, int n){
        int[] ans = new int[n];
        Arrays.fill(ans, Integer.MAX_VALUE / 2);
        ans[start] = 0;

        Queue<Integer> queue = new ArrayDeque<>();
        queue.offer(start);

        while (!queue.isEmpty()){
            int a = queue.poll();

            for(int[] temp : adj[a]){
                int b = temp[0], bCost = temp[1];
                if(ans[a] + bCost < ans[b]){
                    ans[b] = ans[a] + bCost;
                    queue.offer(b);
                }
            }
        }

        return ans;
    }

新农村

遍历就完事了

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        while (input.hasNextLine()){
            String[] line = input.nextLine().split(" ");
            char startChar = line[0].charAt(0), endChar = line[1].charAt(0);
            int startNum = Integer.parseInt(line[0].substring(1)), endNum = Integer.parseInt(line[1].substring(1));
            List<String> list = new ArrayList<>();

            if(startChar <= endChar && startNum <= endNum){
                while (startChar <= endChar){
                    int num = startNum;
                    while (num <= endNum){
                        list.add(startChar+""+num);
                        ++num;
                    }
                    startChar++;
                }
            }

            System.out.println(list);
        }
    }
#中兴##笔试##2023校招#
全部评论
显示未通过全部用例会有分吗
点赞 回复 分享
发布于 2022-09-01 22:23 江苏
能用本地IDE吗楼主
点赞 回复 分享
发布于 2022-09-01 19:49 浙江
中兴笔试不能看通过多少吧😂
点赞 回复 分享
发布于 2022-08-24 20:46 浙江
大佬投递的什么岗位呀
点赞 回复 分享
发布于 2022-08-24 20:44 北京

相关推荐

03-24 00:03
门头沟学院 Java
恶龙战士:实习经历写的不行,需要改,不管是改成主业务还是主技术都可以
点赞 评论 收藏
分享
评论
11
27
分享

创作者周榜

更多
牛客网
牛客企业服务