当前位置: 首页 > 面试经验 >

小红书3.26笔试 后端

优质
小牛编辑
96浏览
2023-03-28

小红书3.26笔试 后端

100% 0% 100%

下午头昏脑胀的,大概率寄了

T1

映射一下,搞回去


public class T1 {

static String str = "abcdefghijklmnopqrstuvwxyz";
static Map<Character, Integer> map = new HashMap<>();
public static void main(String[] args) {
for (int i = 0; i < str.length(); i++) {
map.put(str.charAt(i), i);
}

Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.nextLine();
String s = in.nextLine();
StringBuilder res = new StringBuilder();
for(char c : s.toCharArray()) {
res.append(gao(gao(gao(c))));
}
System.out.println(res.toString());
}
static char gao(char c) {
int idx = map.get(c);
return idx == 0 ? str.charAt(str.length()-1) : str.charAt(idx-1);
}
}

T2

没思路

T3

嗯模拟,没看到下标从1开始,debug了大半个小时。。。


public class T3 {
static int[] nums;
static int[] left;
static int[] right;
static int[] targets;
static char[] ops;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.nextLine();
nums = new int[n];
for (int i = 0; i < n; i++) {
nums[i] = in.nextInt();
}

int m = in.nextInt();
left = new int[m];
right = new int[m];
targets = new int[m];
for (int i = 0; i < m; i++) {
left[i] = in.nextInt();
}
for (int i = 0; i < m; i++) {
right[i] = in.nextInt();
}
in.nextLine();
String str = in.nextLine();
ops = str.toCharArray();
String[] sss = in.nextLine().split(" ");
for (int i = 0; i < sss.length; i++) {
targets[i] = Integer.parseInt(sss[i]);
}

for (int i = 0; i < m; i++) {
gao(i, left[i]-1, right[i]-1);
}

StringBuilder res = new StringBuilder();
for (int i = 0; i < n; i++) {
res.append(nums[i]);
res.append(" ");
}
System.out.println(res.substring(0, res.length()-1));
}

static void gao(int i, int l, int r) {
char op = ops[i];
int num = targets[i];
for (int k = l; k <= r ; k++) {
switch (op) {
case '|':
nums[k] |= num;
break;
case '&':
nums[k] &= num;
break;
case '=':
nums[k] = num;
break;
default:
break;
}
}
}
}

#我的实习求职记录#
 类似资料: