为什么华为机试第二题只有45%啊,哭了

package huaweishixi24.B;

import java.util.*;


/*

4 5
11100 00111 10111 01111


2 10
1011100111 1011101101

 */

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);



        int n = sc.nextInt() , m = sc.nextInt();

        Map<Integer,String> map = new HashMap<>();
        // 进球总数多
        Map<Integer, Integer> order1 = new HashMap<>();


        // 连续进球数

        Map<Integer, Integer> order2 = new HashMap<>();

        //0的优先次序
        Map<Integer, List<Integer>> order3 = new HashMap<>();

        List<List<Integer>> orderlist = new ArrayList<>();
        //总排序
        Map<Integer,List<List<Integer>> > order4 = new HashMap<>();

        for(int i = 0 ; i <  n ; ++i){

            String s = sc.next();

            int count1 = 0;
            int count2 = 0;
            int maxcount2 = 0;
            List<Integer> list = new ArrayList<>();

            // 进球总数多
            for(int j = 0 ; j < m ; ++j ){

                if(s.charAt(j) == '1'){
                    count1++;
                }
//                if(j == 0 && s.charAt(j) == '1'){
//                    count2++;
//                    maxcount2 = Math.max(count2,maxcount2);
//                }

                if(s.charAt(j) == '1' && j > 0 && s.charAt(j-1) == '1'){
                    count2++;
                    maxcount2 = Math.max(count2,maxcount2);
                }

                if(s.charAt(j) == '0'){
                    count2 = 0;
                    list.add(j);
                }

            }

            map.put(i,s);
            order1.put(i,count1);
            order2.put(i,maxcount2);
//            if(list.size() == 0){
//
//            }

            order3.put(i,list);

            List<Integer> o1 = new ArrayList<>();
            o1.add(count1);
            List<Integer> o2 = new ArrayList<>();
            o2.add(maxcount2);
            List<List<Integer>> temp = new ArrayList<>();
            temp.add(o1);
            temp.add(o2);
            temp.add(list);


            order4.put(i,temp);

        }


        List <Map.Entry<Integer, List<List<Integer>>>> list4 = new ArrayList<>(order4.entrySet());

        Collections.sort(list4, new Comparator<Map.Entry<Integer, List<List<Integer>>>>() {
            @Override
            public int compare(Map.Entry<Integer, List<List<Integer>>> o1, Map.Entry<Integer, List<List<Integer>>> o2) {
                List<List<Integer>> value1 = o1.getValue();
                List<List<Integer>> value2 = o2.getValue();
                List<Integer> o11 = value1.get(0);
                List<Integer> o12 = value1.get(1);
                List<Integer> o13 = value1.get(2);
                List<Integer> o21 = value2.get(0);
                List<Integer> o22 = value2.get(1);
                List<Integer> o23 = value2.get(2);
                if(o11.get(0) != o21.get(0)){
                    return o21.get(0) - o11.get(0);
                }else if(o12.get(0) != o22.get(0)){
                    return o22.get(0) - o12.get(0);
                }else{
                    for(int i = 0 ; i < o13.size() ; ++i){
                        if(o13.get(i) != o23.get(i)){
                            return o23.get(i) - o13.get(i);
                        }
                    }
                }
                return o1.getKey()-o2.getKey();
            }
        });

        // 输出id

        for (int i = 0; i < n; i++) {

            if(i < n-1){
                System.out.print(list4.get(i).getKey()+1 + " ");
            }
            if(i == n-1){
                System.out.println(list4.get(i).getKey()+1);
            }
        }


        // 进球总数多 , 全部进球都是1特判



        // 连续进球数


        //0的优先次序


        //id小

//        System.out.println(map);



    }

}

#华为##牛客帮帮团来啦!有问必答#
全部评论
我看不懂Java😭,可以给你看看我的py写的,我当时100过的
2
送花
回复
分享
发布于 04-28 21:37 湖北
od吗佬
点赞
送花
回复
分享
发布于 04-24 22:29 广东
秋招专场
校招火热招聘中
官网直投
哥们第三题是啥呀,leetcode有原题吗。当时都没时间看
点赞
送花
回复
分享
发布于 05-12 16:57 湖北

相关推荐

1 4 评论
分享
牛客网
牛客企业服务