0326小红书笔试

Q1

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        char[] cs = scan.next().toCharArray();
        for (int i = 0; i < n; i++) {
            cs[i] = (char) ('a' + ((cs[i] - 'a' - 3 + 26) % (26)));
        }
        System.out.println(new String(cs));
    }
}

Q2

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int t = scan.nextInt();
        while (t-- > 0){
            int n = scan.nextInt(), k = scan.nextInt();
            int ans, cnt = 0;
            for (int i = 0, j = 1; i < n; i++) {
                if (j == scan.nextInt()) {
                    cnt++;
                    j++;
                }
            }
            ans = (int) Math.ceil((n - cnt) * 1. / k);
            System.out.println(ans);
        }
    }
}

Q3

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long[] nums = new long[n];
        for (int i = 0; i < n; i++) nums[i] = scan.nextLong();
        int m = scan.nextInt();
        int[] lefts = new int[m], rights = new int[m];
        char[] ops;
        long[] params = new long[m];
        for (int i = 0; i < m; i++) lefts[i] = scan.nextInt() - 1;
        for (int i = 0; i < m; i++) rights[i] = scan.nextInt() - 1;
        ops = scan.next().toCharArray();
        for (int i = 0; i < m; i++) params[i] = scan.nextLong();
        for (int i = 0; i < m; i++) {
            int l = lefts[i], r = rights[i];
            char op = ops[i];
            long p = params[i];
            if (op == '|') {
                for (int j = l; j <= r && j < n; j++) nums[j] |= p;
            } else if (op == '&') {
                for (int j = l; j <= r && j < n; j++) nums[j] &= p;
            } else if (op == '=') {
                for (int j = l; j <= r && j < n; j++) nums[j] = p;
            }
        }
        for (int i = 0; i < n; i++) System.out.print(nums[i] + " ");
    }
}

#小红书笔试#
全部评论
你这是啥岗位的笔试题
点赞 回复 分享
发布于 2023-03-27 09:27 黑龙江
第二题想了40min不会,没想到代码这么简洁
点赞 回复 分享
发布于 2023-03-27 16:31 上海
笔试题共有几道?给了多长时间做题呢
点赞 回复 分享
发布于 2023-03-28 19:21 四川
请问笔试的时候可以切换到自己电脑上的本地IDE吗?
点赞 回复 分享
发布于 2023-04-07 21:35 辽宁
请问题目是什么啊
点赞 回复 分享
发布于 2023-04-08 12:22 重庆

相关推荐

Pandaileee:校友加油我现在也只有一个保底太难了
点赞 评论 收藏
分享
10-25 00:32
香梨想要offer:感觉考研以后好好学 后面能乱杀,目前这简历有点难
点赞 评论 收藏
分享
2 10 评论
分享
牛客网
牛客企业服务