爱奇艺算法岗的笔试题就硬尬么???

本来看Death Note呢,想起来有笔试,结果做着有些浪费时间了。。。
第一题代码尬过去了,我都觉得无语。
public static String getRes(String sentence, String[] word2) {

    StringBuilder sent = new StringBuilder();
    Map<Integer, String> map = new HashMap<>();
    String[] word1 = sentence.split("\\s+");

    for (String word : word1)
        sent.append(word);

    for (String word : word2) {

        int idx = sent.indexOf(word, 0);
        while (idx != -1) {

            map.put(idx, word);
            idx = sent.indexOf(word, idx + 1);
        }
    }


    StringBuilder res = new StringBuilder();

    int cur = 0, start = 0;

    for (int i = 0; i < sentence.length(); i++) {

        char ch = sentence.charAt(i);

        if (map.containsKey(start)) {

            res.append(" " + map.get(start) + " ");
            start += map.get(start).length();
        } else {
            res.append(ch);

            if (ch != ' ') {

                cur++;
                start++;
            }
        }

        boolean flag = false;

        while (cur < start) {

            flag = true;

            if (sentence.charAt(i) != ' ')
                cur++;

            i++;
        }

        if (flag)
            i--;
    }

    return res.toString().trim();
}
枉我第一题还写了半天,看其他朋友说直接输出就可以AC?
第二题不给行数?
Scanner scan = new Scanner(System.in);
int n = Integer.parseInt(scan.nextLine());
System.out.println(scan.nextLine());
我直接尬过去33%
#笔试题目##爱奇艺#
全部评论
请问第一题应该咋做。。。
1
送花
回复 分享
发布于 2020-08-23 16:26
第二题楼主写的这是啥意思,我也想尬一下,但是看不懂
点赞
送花
回复 分享
发布于 2020-08-23 16:29
秋招专场
校招火热招聘中
官网直投
第一题怎么做
点赞
送花
回复 分享
发布于 2020-08-23 16:32
第二题瞎写了个 结果AC了 吐了 import textwrap import sys _ = input().strip() l = '\n&(392)#39;.join([x.strip() for x in sys.stdin.readlines()]) print(textwrap.fill(l, width=int(_)))
点赞
送花
回复 分享
发布于 2020-08-23 16:33
你第二题如果每行补上空格直接ac
点赞
送花
回复 分享
发布于 2020-08-23 16:38

相关推荐

2 收藏 评论
分享
牛客网
牛客企业服务