爱奇艺提前批笔试

第一题:

select * from (select  demand_id, count(demand_id) as count from Task  group by demand_id) t where count >=2

第二题:

public class 爱奇艺 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String line = in.nextLine();
        String[] split = line.split(":");
        int k = Integer.parseInt(split[1]);
        String[] num = split[0].split(",");
        int[]arr = new int[num.length-k+1];
        int sum = 0,t=1;
        double max = 0.0;
        for (int i = 0; i < k; i++) {
            sum += Integer.parseInt(num[i]);
        }
        arr[0] = sum;
        for (int i = k; i <num.length ; i++) {
            sum = sum-Integer.parseInt(num[i-k])+Integer.parseInt(num[i]);
            arr[t++] = sum;
        }
        for (int i = arr.length-1; i>0; i--) {
            max = Math.max(max,(arr[i]-arr[i-1])/1.0/arr[i-1]);
        }
        System.out.println(String.format("%.2f",max*100)+"%");
    }
}

第三题

题目:给定数组 rain = [ 1,2,0,0,1,2] , 数组中

数字大于0 代表(1, 2 表示天数 i;arr[0]>0 、arr[1] >0 ; arr[0] = 1:表示 1 号湖泊第 1**天下雨** ,arr[1] = 2:表示 2 号湖泊第 2**天下雨** )下雨,*不能进行抽水 *

数字小于 0 表示 **当天可以对以前下过雨的湖泊进行抽水(一次抽完),当湖泊有水**再继续下雨则发生洪水返回空数组

样例 :1,2,0,0,2,1

输出:-1,-1,2,1,-1,-1

样例 :1,2,0,0,2,2

输出:[] (不能提起抽水,即抽水一定是在下雨之后)
图片说明

public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] day = in.nextLine().replace("[","").replace("]","").split(",");
        List<Integer> sun = new ArrayList<>();  // 可以抽水的日期 <日期>
        HashMap<String,Integer> rain = new HashMap<>();  // 湖泊下雨记录 <湖泊:日期>
        HashMap<Integer,String> flush = new HashMap<>();  // 抽水记录 <日期:湖泊>
        for (int i = 0; i < day.length; i++) {
            if (day[i].equals("0")){ // 晴天
                sun.add(i);
            }else {  // 雨天
                if(rain.containsKey(day[i])) // day[i] 号湖泊之前下过雨,则找>i的第一次可以抽水的日期
                {
                    int rain_day = rain.get(day[i]);  // 找到上次下雨的时间
                    for (int j = 0; j < sun.size(); j++) {  // 遍历可以抽水的日期
                        if(sun.get(j)>rain_day){   // 找到上次下雨可以抽水的日期
                            flush.put(sun.get(j),day[i]);  // 记录抽水
                            sun.remove(j);  // 移除抽水的日期
                            rain.put(day[i],i);  // 跟新湖泊下雨时间
                            break; //抽水成功终止循环
                        }
                    }
                    if (rain.get(day[i])!=i){  // 判断是否抽水成功
                        System.out.println("[]");
                        return;
                    }
                }
                else {
                    rain.put(day[i],i);  // 记录该湖泊第一次下雨时间
                }
            }
        }
        // 处理结果
        int[] res = new int[day.length];
        for (int j = 0; j < res.length; j++) {
            if (flush.containsKey(j)) {
                res[j] = Integer.parseInt(flush.get(j));
            }else if (day[j].equals("0")) res[j] = 1;
            else res[j] = -1;
        }
        System.out.println(Arrays.toString(res));
    }

第四题

public class 爱奇艺 {
    public static void main(String[] args) throws InterruptedException {
        Solution s = new Solution();
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 10,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue(10000));
        final Scanner reader = new Scanner(System.in);
        final String next = reader.next();
        List lines = Arrays.stream(next.split(",")).map(str -> new StringLine(str))
                .collect(Collectors.toList());
        List result = s.translateAll(lines, "", threadPoolExecutor);
        String resultString = result.stream().map(l -> l.toString()).collect(Collectors.joining(","));
        System.out.println(resultString);
        reader.close();
        threadPoolExecutor.shutdown();
    }
    public interface Line {
        /**
         * translate the line to the specific language
         * @param language - the language to translate
         * @return the line of translated by the {@code language} */
        Line translate(String language);
    }
    public static class Solution {
        /**
         * translate the all lines to the specific language
         * @param lines the text lines of episode
         * @param language the language to translate
         * @return the lines of translated by the {@code language} */
        public List translateAll(List lines, String language, Executor executor) throws InterruptedException {
            Job job = new Job();
            for (Line line : lines) {
                Callable callable = () -> {
                    return line.translate(language);
                };
                job.newTask(callable);
            }
            job.execute(executor);
            return job.get();
        }
    }
    public static class Job {
        List res = new ArrayList();
        Stack task = new Stack();
        public void newTask(Callable runnable) {
            //待实现
            task.add(runnable);
        }
        public void execute(Executor executor){
            //待实现
            while (!task.isEmpty()){
                ThreadPoolExecutor executor1 = (ThreadPoolExecutor) executor;
                Future future = executor1.submit((Callable) task.pop());
                StringLine o = null;
                try {
                    o = (StringLine) future.get();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (ExecutionException e) {
                    e.printStackTrace();
                }
                res.add(0, (V) o);
            }
        }
        public List get() throws InterruptedException {
            //待实现
            return res;
        }
    }
    /**
     * translate the string line to upper case
     */
    public static class StringLine implements Line {
        private String text;
        public StringLine(String text) {
            this.text = text;
        }
        @Override
        public Line translate(String language) {
            return new StringLine(text.toUpperCase());
        }
        @Override
        public String toString() {
            return text;
        }
    }
}
#爱奇艺22届提前批启动##笔经##爱奇艺#
全部评论
第三题求解
点赞 回复 分享
发布于 2021-08-01 21:24
我今天投了提前批,怎么查不到投递记录呀,你碰到这情况吗
点赞 回复 分享
发布于 2021-08-02 16:55
楼主,请问你现在官网状态是啥?
点赞 回复 分享
发布于 2021-08-05 16:56

相关推荐

10-15 09:13
已编辑
天津大学 soc前端设计
点赞 评论 收藏
分享
3 16 评论
分享
牛客网
牛客企业服务