联想笔试记录

联想2023校招-后端开发

编程题1-剪刀石头布

image-20220810212412491

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.util.Scanner;

public class Main {
static String[] choices = new String[]{"Rock", "Scissor", "Paper"};
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
scanner.nextLine();
String s1 = scanner.nextLine();
String s2 = scanner.nextLine();
String[] alice = s1.split(" "), bob = s2.split(" ");
int ans1 = 0, ans2 = 0;
for (int i = 0; i < n; i++) {
int score = isWin(alice[i], bob[i]);
if (score == 0)
continue;
if (score > 0)
ans1++;
else
ans2++;
}
System.out.println(ans1 + " " + ans2);
}

public static int isWin(String s1, String s2) {
if (s1.equals(choices[0]) && s2.equals(choices[1]))
return 1;
if (s1.equals(choices[1]) && s2.equals(choices[2]))
return 1;
if (s1.equals(choices[2]) && s2.equals(choices[0]))
return 1;
if (s1.equals(s2))
return 0;
return -1;
}
}

image-20220810213722418

编程题2

image-20220810212433469

image-20220810212446074

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
scanner.nextLine();
String[] days = new String[n];
for (int i = 0; i < n; i++) {
// scanner.nextLine();
days[i] = scanner.nextLine();
}

TreeSet<String> sortedWords = new TreeSet<>();
for (String day : days) {
String[] words = day.split(" ");
for (String word : words) {
sortedWords.add(word);
}
}
int cnt = 0;
while(!sortedWords.isEmpty()) {
String temp = sortedWords.pollFirst();
if (cnt + temp.length() > 50) {
System.out.print("\n" + temp + " ");
cnt = 0;
cnt += temp.length() + 1;
} else {
System.out.print(temp + " ");
cnt += temp.length() + 1;
}
}
}
}

image-20220810215212581


联想2023校招-python后端方向
http://example.com/2022/08/11/笔试记录/联想2023校招-python后端方法/
作者
madao33
发布于
August 11, 2022
许可协议