华为OD机试真题 C++ 实现【西天取经】【2023.3 Q1 新题】 您所在的位置:网站首页 唐僧取经的目的地 华为OD机试真题 C++ 实现【西天取经】【2023.3 Q1 新题】

华为OD机试真题 C++ 实现【西天取经】【2023.3 Q1 新题】

2024-06-29 10:33| 来源: 网络整理| 查看: 265

2023华为od机试C卷【剩余银饰的重量】Java 实现

qq_42003397: 感觉优先级队列是不是好用点 [code=java] Scanner scanner = new Scanner(System.in); int count = scanner.nextInt(); scanner.nextLine(); String[] input = scanner.nextLine().split(" "); PriorityQueue priorityQueue = new PriorityQueue((Comparator.reverseOrder())); for (int i = 0; i < count; i++) { Integer weight = Integer.parseInt(input[i]); priorityQueue.add(weight); } while (priorityQueue.size() >= 3) { Integer z = priorityQueue.poll(); Integer y = priorityQueue.poll(); Integer x = priorityQueue.poll(); int remain = 0; if (x.equals(y) && !y.equals(z)) { remain = z - y; } else if (!x.equals(y) && y.equals(z)) { remain = y - x; } else if (!x.equals(y) && !y.equals(z)) { remain = Math.abs((z - y) - (y - x)); } else { continue; } [/code]

2023华为od机试C卷【内存冷热标记】Java 实现

qq_42003397: 考试可以这么写不 public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int num = scanner.nextInt(); HashMap map = new HashMap(); scanner.nextLine(); String[] input = scanner.nextLine().split(" "); for (int i = 0; i < num; i++) { Integer pageCount = Integer.parseInt(input[i]); if (!map.containsKey(pageCount)) { map.put(pageCount, 1); } else { map.put(pageCount, map.get(pageCount) + 1); } } int threshold = scanner.nextInt(); List result = map.entrySet().stream() .filter(o -> o.getValue() >= threshold) .sorted((o1, o2) -> o2.getValue() - o1.getValue()) .map(Map.Entry::getKey).collect(Collectors.toList()); System.out.println(result.size()); result.forEach(System.out::println); }

2024华为od机试C卷【学生重新排队、小朋友分组最少调整次数】C++ 实现

2024剑指offer: 非常感谢你的关注,这里推荐下本人的华为OD机试专栏: * 专栏链接:https://blog.csdn.net/goldarmour/category_12190134.html * 真题目录:https://blog.csdn.net/goldarmour/article/details/129807099 * C卷D卷:https://blog.csdn.net/goldarmour/article/details/138328179

【100%通过率】华为OD机试真题 C++ 实现【匿名信】【2022.11 Q4 新题】

weixin_42092558: 64行和65行间添加int found=find(newpaper.begin(),newspaper.end(),x);newspaper.erase(newspaper.begin()+found);再把后面那个If里find函数改成found这样应该就可以了

华为OD机试真题 C++ 实现【任务调度】【2022.11 Q4 新题】

weixin_42092558: 题目中“相同优先级的任务不会同时到达”不代表“任务不会同时到达”,代码中函数好像只会记录某一时间到达的第一个任务吧



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有