感觉华为的编程题考查的不是人的编程能力啊。。。

输入输出调试半小时是什么鬼。。#华为#
全部评论
模块依赖关系分析    点击链接看源码
点赞 回复 分享
发布于 2017-08-19 13:41
public class NIOTest { public static void main(String[] args) { Scanner sc = new Scanner(System.in); ArrayList<Node> res = new ArrayList<>(); HashMap<String, Node> relation = new HashMap<>(); boolean flag = true; while (sc.hasNext()) { String str = sc.nextLine(); parse(str, relation); if (str.charAt(str.length() - 1) != ',') break; } while (!relation.isEmpty() && flag == true) { flag = false; Node node = null; for (Map.Entry<String, Node> entry : relation.entrySet()) { Node cur = entry.getValue(); if (cur.degree == 0) { node = cur; break; } } if (node != null) { for (Node temp : node.relation) { temp.degree--; } res.add(node); relation.remove(node.name); flag = true; } } for (Map.Entry<String, Node> entry : relation.entrySet()) { res.add(entry.getValue()); } Collections.sort(res, new Comparator<Node>() { public int compare(Node a, Node b) { return a.name.compareTo(b.name); } }); for (int i = 0; i < res.size() - 1; i++) { boolean b = res.get(i).degree == 0 ? false : true; System.out.println("{" + res.get(i).name + ", " + b + "},"); } boolean b = res.get(res.size() - 1).degree == 0 ? false : true; System.out.println("{" + res.get(res.size() - 1).name + ", " + b + "}"); } public static void parse(String str, HashMap<String, Node> relation) { String[] strs = str.split(","); String A = strs[0].substring(1, strs[0].length()); String B = strs[1].substring(1, strs[1].length() - 1); Node nodeA = relation.get(A); if (nodeA == null) { nodeA = new Node(A, null, 1); relation.put(A, nodeA); } else { nodeA.degree++; } Node nodeB = relation.get(B); if (nodeB == null) { nodeB = new Node(B, nodeA, 0); relation.put(B, nodeB); } else { nodeB.relation.add(nodeA); } } public static class Node { public String name; public LinkedList<Node> relation = new LinkedList<>(); public int degree; public Node (String name, Node relation, int degree) { this.name = name; if (relation != null)this.relation.add(relation); this.degree = degree; } } }
点赞 回复 分享
发布于 2017-08-17 10:03
感觉华为考的是编程思想,还有格式,不是AC,估计和网易一样,一张一张的试卷筛选
点赞 回复 分享
发布于 2017-08-17 08:33
问个问题 为啥我这次 就没有收到 笔试  是不是我春招华为挂了 就没机会了???
点赞 回复 分享
发布于 2017-08-16 22:29
为什么你们可以不按照他规定的接口来写?
点赞 回复 分享
发布于 2017-08-16 22:28
第二题本地正常的JAVA代码,贴上去编译不过去,改了Main了导包了,直接跪!
点赞 回复 分享
发布于 2017-08-16 22:16
我66 0 33.、。是不是稳挂
点赞 回复 分享
发布于 2017-08-16 22:09
最后2道都没有百分之100,唉
点赞 回复 分享
发布于 2017-08-16 21:55
通过率多少你
点赞 回复 分享
发布于 2017-08-16 21:55
public class NIOTest { public static void main(String[] args) { Scanner sc = new Scanner(System.in); ArrayList<Node> res = new ArrayList<>(); HashMap<String, Node> relation = new HashMap<>(); boolean flag = true; while (sc.hasNext()) { String str = sc.nextLine(); parse(str, relation); if (str.charAt(str.length() - 1) != ',') break; } while (!relation.isEmpty() && flag == true) { flag = false; Node node = null; for (Map.Entry<String, Node> entry : relation.entrySet()) { Node cur = entry.getValue(); if (cur.degree == 0) { node = cur; break; } } if (node != null) { for (Node temp : node.relation) { temp.degree--; } res.add(node); relation.remove(node.name); flag = true; } } for (Map.Entry<String, Node> entry : relation.entrySet()) { res.add(entry.getValue()); } Collections.sort(res, new Comparator<Node>() { public int compare(Node a, Node b) { return a.name.compareTo(b.name); } }); for (int i = 0; i < res.size() - 1; i++) { boolean b = res.get(i).degree == 0 ? false : true; System.out.println("{" + res.get(i).name + ", " + b + "},"); } boolean b = res.get(res.size() - 1).degree == 0 ? false : true; System.out.println("{" + res.get(res.size() - 1).name + ", " + b + "}"); } public static void parse(String str, HashMap<String, Node> relation) { String[] strs = str.split(","); String A = strs[0].substring(1, strs[0].length()); String B = strs[1].substring(1, strs[1].length() - 1); Node nodeB = relation.get(B); if (nodeB == null) { nodeB = new Node(B, null, 1); relation.put(B, nodeB); } else { nodeB.degree++; } Node nodeA = relation.get(A); if (nodeA == null) { nodeA = new Node(A, nodeB, 0); relation.put(A, nodeA); } else { nodeA.relation.add(nodeB); } } public static class Node { public String name; public LinkedList<Node> relation = new LinkedList<>(); public int degree; public Node (String name, Node relation, int degree) { this.name = name; if (relation != null)this.relation.add(relation); this.degree = degree; } } }
点赞 回复 分享
发布于 2017-08-16 21:51
第二题,很简单的拓扑排序,为了表示形式,愣是花了太长时间
点赞 回复 分享
发布于 2017-08-16 21:38

相关推荐

01-21 20:09
武汉大学 Java
点赞 评论 收藏
分享
2025-12-12 19:01
南京航空航天大学 C++
秋招没咋投,准备&nbsp;wxg&nbsp;转正之后摆烂了。结果不堪字节&nbsp;HR&nbsp;的骚扰还是面了一下字节。之前想去字节的时候怎么面都挂。现在想着随便面一下结果三面技术面都意外顺利还有加面。十月中旬字节发了意向,wxg&nbsp;转正结果无响应。十月底字节拉了保温群,wxg&nbsp;口头通过,系统显示考核中。十一月初和字节&nbsp;ld&nbsp;交流之后得知&nbsp;base&nbsp;居然能选海外,甚至能小&nbsp;wlb&nbsp;一下,wxg&nbsp;无响应无人联系。十一月中旬把字节&nbsp;base&nbsp;转到了海外,wxg&nbsp;流程灰了,一问超时忘处理了,过两天又变考核中了。十一月下旬字节换了海外&nbsp;HR&nbsp;对接,问了期望薪资,wxg&nbsp;考核终于显示通过,无&nbsp;HR&nbsp;保温,无其他保温。十一月底给字节报了个天价,想吓吓他们,同时告诉微信字节要开了,微信无响应。同样十一月底字节&nbsp;HR&nbsp;告诉我确实给不到那么高,但是能拿期权补上,问能不能接受。微信无响应。同样十一月底字节&nbsp;HR&nbsp;告知了具体方案,符合预期。&nbsp;微信无响应。十二月上旬催&nbsp;wxg&nbsp;不开我就盲拒了,wxg&nbsp;HR&nbsp;火急火燎的打电话问情况,问期望。我给了一个不算夸张的总包数字,因为今年市场在涨,过了三天还不联系我,我再催,约时间下午打电话,非得在我给出的数字上压下去几万,微信又不差这点,为什么不能满足我,让我没有拒绝的理由呢?一番纠结抗争,求稳还是追求挑战,最终选择接受迎接新的挑战,因为堂吉诃德永远不会停下脚步!回想起来,在&nbsp;wxg&nbsp;谈薪的阶段,我认为并没有给予我一定的重视,即使&nbsp;HR&nbsp;表示我在实习期间的表现和之前的面评都很靠前。也没有感觉到想要争取我,虽然我表示拒了&nbsp;offer&nbsp;之后要给我加面委定&nbsp;t6&nbsp;再涨,但我三个月没面试让我面面委那就是白给,还是算了。有缘再见了我亲爱的&nbsp;wxg,再见了曾经的梦中情厂,再见亲爱的&nbsp;mt,再见亲爱的朋友们。也再见,北京的一切。我想润了。秋招结束,卸载牛客,下一个三年,下一个五年,下一个十年后再来看看。
面试中的大熊猫爱吃薯...:我嫉妒得狗眼通红
点赞 评论 收藏
分享
评论
点赞
4
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务