网易雷火8/14后端折磨笔试

第一道题:遍历x的可能取值,然后统计方案数。
第二题代码:private static Map<String, String> map = new HashMap<>();
private static Map<String, String> map = new HashMap<>(); public static void main(String[] args) {
   Scanner in = new Scanner(System.in); //            
// 注意 hasNext  hasNextLine 的区别  int w = in.nextInt();
   in.nextLine(); map.put("#R", "FF0000"); map.put("#G", "00C932"); map.put("#B", "0000FF"); map.put("#K", "000000"); map.put("#Y", "FFFF00"); map.put("#W", "FFFFFF"); map.put("#P", "FF88FF"); while (w-- > 0) {
        String str = in.nextLine();
        Stack<String> stack = new Stack<>(); char[] chars = str.toCharArray(); if (chars.length == 0) continue; int start = 0; boolean p = false; for (int i = 0; i < chars.length; i++) { if (chars[i] == '#') { if (i == chars.length - 1) break; if (chars[i+1] == 'n') { if (start != 0 && !stack.isEmpty() && !getStr(chars, start, i).equals("")) {
                                p = true;
                                System.out.print(getStr(chars, start, i));
                                System.out.println(" " + stack.peek());
                            } if (!stack.isEmpty()) stack.pop(); if (!stack.isEmpty()) start = i + 2; else start = 0;
                            i++; continue;
                        }
                        String s = check(chars, i); //                     System.out.println(s);  if (!s.equals("")) { if (start != 0 && !stack.isEmpty() && !getStr(chars, start, i).equals("")) {
                                p = true;
                                System.out.println(getStr(chars, start, i)+" " + stack.peek());
                            }
                            stack.push(s); if (map.containsKey("#" + chars[i+1])) {
                                start = i + 2;
                                i++;
                            } else {
                                start = i + 8;
                                i += 7;
                            }
                        }
                    }
                } if (start != 0 && !stack.isEmpty() && !getStr(chars, start, chars.length).equals("")) {
                    p = true;
                    System.out.println(getStr(chars, start, chars.length) + " " + stack.peek());
                } if (!p) System.out.println("empty");
            }
        } public static String check(char[] chars, int i) { if (i == chars.length - 1) return ""; char c = chars[i+1]; if (map.containsKey("#" + c)) return map.get("#"+c); if (c == 'C') { if (i + 7 > chars.length) return "";
                StringBuilder sb = new StringBuilder(); for (int j = i+2; j <= i + 7; j++) {
                    sb.append(chars[j]); if ((chars[j] >= '0' && chars[j] <= '9') || (chars[j] >= 'A' && chars[j] <= 'F')) continue; else return "";
                } return sb.toString();
            } return "";
        } public static String getStr(char[] chars, int start, int j) {
            StringBuilder sb = new StringBuilder(); for (int i = start; i < chars.length && i < j; i++) {
                sb.append(chars[i]);
            } return sb.toString();
        }



#网易雷火2023秋招笔试虐我的瞬间#
全部评论
我想问一下,求出序列中除去42的最大值与最小值,令最大值减去X小于等于90,同时令最小值减去X大于等于65,同时保证X大于等于0,在这个范围内的X应该都是满足条件的,但是写出来连测试用例都没过,后面改成X总是取最大值减去90,才把准确率刷到86%,我是很想知道我上面的思路有什么问题吗,或者谁能给我解释一下那个用例为什么只有一个解,按照我上面的思路X应该有四个解才对啊
点赞 回复 分享
发布于 2022-08-15 00:38
看完第一题,后面的看了几眼直接交卷了
点赞 回复 分享
发布于 2022-08-14 17:37
太折磨了,只做了一道,剩下都不会
点赞 回复 分享
发布于 2022-08-14 17:35

相关推荐

不愿透露姓名的神秘牛友
昨天 22:30
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

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