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

输入输出调试半小时是什么鬼。。#华为#
全部评论
模块依赖关系分析    点击链接看源码
点赞 回复 分享
发布于 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

相关推荐

昨天 11:26
清华大学 Java
打开电脑,思绪又回到了7月份刚开始的时候,感觉这个月过的如梦如幻,发生了太多事,也算是丰富了我本就是平淡的人生吧太早独立的我习惯了一切都是自己做决定,拥有绝对的决定权,而且永远不会听取别人的建议。我就是那个恋爱四年出轨的男主啦,感觉既然在牛客开了这个头,那我就要做个有始有终的人。从我出轨到结束再到和女朋友和好如初真的太像一场梦了,短短的一个月我经历了太多,也成长了很多,放下了那些本就不属于我的,找回了那些我不该放弃的。我的人生丰富且多彩,但人不能一直顺,上天总会让你的生活中出点乱子,有好有坏,让你学会一些东西,让你有成长。我和女朋友的恋爱四年太过于平淡,日常除了会制造一些小浪漫之外,我们的生活...
段哥亡命职场:不得不说,我是理解你的,你能发出来足见你是个坦诚的人,至少敢于直面自己的内心和过往的过错。 这个世界没有想象中那样非黑即白,无论是农村还是城市,在看不见的阴影里,多的是这样的事。 更多的人选择站在制高点去谩骂,一方面是社会的道德是需要制高点的,另一方面,很多人不经他人苦,却劝他人善。 大部分的我们,连自己生命的意义尚且不能明晰,道德、法律、困境,众多因果交织,人会迷失在其中,只有真的走出来之后才能看明白,可是没走出来的时候呢?谁又能保证自己能走的好,走的对呢? 可是这种问题有些人是遇不到的,不去追寻,不去探寻,也就没了这些烦恼,我总说人生的意义在过程里,没了目标也就没了过程。 限于篇幅,没法完全言明,总之,这世界是个巨大的草台班子,没什么过不去了,勇敢面对,革故鼎新才是正确,祝你早日走出来。查看图片
点赞 评论 收藏
分享
评论
点赞
4
分享

创作者周榜

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