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] + " "); } }#小红书笔试#