爱奇艺 2021/08/22 测试开发 校招 笔试 完整题目
开始的时候就让选 A 卷(JAVA为主),B 卷(JS为主),我选的 JAVA
选择题有单选也有多选题,内容有Java、Spring Boot、计网、操作系统、数据库、Python
20 道选择题(40分),4道编程题(60分),共计 2 小时,编程题可以跳出网页在外部 IDE 编写代码,然后粘贴进去。
女生数量最多的专业名称和对应的女生人数(10分)
这是一个 MySQL 编程题,因为网站不会显示输出的结果也无法调试,只会显示你的答案是否正确。
考试中途有个提示:mysql编程题请注意,表名和字段名严格区分大小写。
题目描述
现有如下MySQL数据表,请写出合适的SQL语句,查询出女生数量最多的前三个专业名称和对应的女生人数?(gender字段说明:1为男,2为女)。要求查询结果的表头如subject_name, girl_count。
大学学生基本信息表Student_Info
| id | name | gender |
|---|---|---|
| 1 | Kate | 2 |
| 2 | Mary | 2 |
| 3 | Tom | 1 |
| 4 | Jim | 1 |
| 5 | Lily | 2 |
| 6 | Rose | 2 |
| 7 | Lucy | 2 |
| 8 | Meimei | 2 |
专业信息登记表Subject_Register
| student_id | subject_id |
|---|---|
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 4 | 3 |
| 5 | 2 |
| 6 | 4 |
| 7 | 4 |
| 8 | 4 |
专业基本信息表Subject_Info
| id | name |
|---|---|
| 1 | Math |
| 2 | English |
| 3 | Computer |
| 4 | News |
输出描述
查询出女生数量最多的前三个专业名称和对应的女生人数, 要求查询结果的表头如subject_name, girl_count
样例输入
create table Student_Info(id int primary key not null, name varchar(30), gender int); insert into Student_Info(id,name,gender) values(1,'Kate',2); insert into Student_Info(id,name,gender) values(2,'Mary',2); insert into Student_Info(id,name,gender) values(3,'Tom',1); insert into Student_Info(id,name,gender) values(4,'Jim',1); insert into Student_Info(id,name,gender) values(5,'Lily',2); insert into Student_Info(id,name,gender) values(6,'Rose',2); insert into Student_Info(id,name,gender) values(7,'Lucy',2); insert into Student_Info(id,name,gender) values(8,'Meimei',2); create table Subject_Register(student_id int primary key not null, subject_id int); insert into Subject_Register(student_id,subject_id) values(1, 1); insert into Subject_Register(student_id,subject_id) values(2, 2); insert into Subject_Register(student_id,subject_id) values(3, 3); insert into Subject_Register(student_id,subject_id) values(4, 3); insert into Subject_Register(student_id,subject_id) values(5, 2); insert into Subject_Register(student_id,subject_id) values(6, 4); insert into Subject_Register(student_id,subject_id) values(7, 4); insert into Subject_Register(student_id,subject_id) values(8, 4); create table Subject_Info(id int primary key not null, name varchar(30)); insert into Subject_Info(id,name) values(1, 'Math'); insert into Subject_Info(id,name) values(2, 'English'); insert into Subject_Info(id,name) values(3, 'Computer'); insert into Subject_Info(id,name) values(4, 'News');
样例输出
News 3 English 2 Math 1
参考AC代码
作者:Sliding
链接:https://www.nowcoder.com/discuss/715818 (1楼楼中楼)
select Subject_Info.name as subject_name, count(*) as girl_count from Student_Info, Subject_Info, Subject_Register where gender=2 and Student_Info.id=Subject_Register.student_id and Subject_Info.id=Subject_Register.subject_id group by Subject_Info.name having count(*) order by girl_count desc limit 3;
最大振幅计算(10分)
题目描述
在监控与BI报表系统中,我们经常会采集数据指标进行分析,这里的数据往往都是时序数据,对于时序数据,我们可以用一个数组来表示,例如数组下标表示时间顺序,数组的值表示采集的指标数据大小。现在作为分析师的你,得到如下一个任务:在给定一个整数形式的时序数据,求出这个时序里最大的振幅(“落差”)(振幅 = 时序里相邻的“波峰”与“波谷”相差绝对值)
输入描述
一个数组,下标代表x轴的时间顺序,数组里的每个数值代表y轴的具体值
输出描述
整个曲线的相邻波峰与波谷的最大振幅落差
样例输入
1,2,3,8,5,3,6 2,2,3,8,8,6,5,10,7,6 1,2,3,4,5,6
样例输出
7 6 5
参考AC代码
用的双指针
import java.util.Scanner;
public class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String[] nums_str = sc.nextLine().split(",");
int[] nums = new int[nums_str.length];
for (int i = 0; i < nums_str.length; i++) {
nums[i] = Integer.parseInt(nums_str[i]);
}
int start = 0, i = 1, j = 2;
// start 是本次波的起点(单独的一次上升波,或者是下降波)
// i 和 j 是用来比较两个数的,其实 j==i+1,代码懒得改了
int ans = 0, diff = nums[1]-nums[0];
// ans 就是最大的振幅,diff 是两个数之间的差值
while(i <= j && j < nums.length){
if((nums[j] - nums[i]) * diff > 0){ // 如果当前两个数的差值和之前的差值相乘为正,说明现在方向没变(连续上升,或是连续下降)
j++; // 更新指针,向前,匹配前面的数
i++; // 同上
}else{
ans = Math.max(ans, nums[j-1] - nums[start]); // 如果方向发生了改变,那么就获取本次上升或下降的振幅(最末尾的地方 - 起始的地方)
diff = nums[j] - nums[i]; // 更新差值,为下一次判断方向做准备
start = i; // 更新本次上升或下降的起点
i = j; // 更新指针
j = i + 1; // 更新指针
}
}
if(start == 0){ // 如果一直是上升,或是下降
System.out.println(nums[nums.length-1] - nums[0]);
}else{
System.out.println(ans);
}
}
}
} 象棋问题(20分)
考试时中途提示:如果您的编程题有“象棋问题”的话,请注意,输入中包含“n=”这2个字符,需要自行去除。
LeetCode原题:LeetCode 51 N 皇后
题目描述
n 皇后问题研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击(1<=n<=9)。
输入描述
给你一个整数n。
输出描述
返回所有不同的 n 皇后问题的解决方案。每一种解法包含一个不同的 n 皇后问题的棋子放置方案,该方案中 'Q' 和 '.' 分别代表了皇后和空位。
样例输入
n=4
样例输出
[[.Q.., ...Q, Q..., ..Q.], [..Q., Q..., ...Q, .Q..]]
提示
1 <= n <= 9
多线程打印奇偶数(20分)
这道题是要完成函数,主函数已经给出来了。
LeetCode原题:LeetCode 1114 按序打印
import java.util.Scanner;
import java.util.concurrent.Semaphore;
import java.util.function.IntConsumer;
public class Main {
public static void main(String[] args) {
final Scanner reader = new Scanner(System.in);
int n = reader.nextInt();
ZeroEvenOdd zeroEvenOdd = new ZeroEvenOdd(n);
new Thread(() -> {
try {
zeroEvenOdd.printZero(System.out::print);
} catch (InterruptedException e) {
e.printStackTrace();
}
}).start();
new Thread(() -> {
try {
zeroEvenOdd.printEven(System.out::print);
} catch (InterruptedException e) {
e.printStackTrace();
}
}).start();
new Thread(() -> {
try {
zeroEvenOdd.printOdd(System.out::print);
} catch (InterruptedException e) {
e.printStackTrace();
}
}).start();
}
}
class ZeroEvenOdd {
private int n;
public ZeroEvenOdd(int n) {
this.n = n;
}
// printNumber.accept(x) outputs "x", where x is an integer.
public void printZero(IntConsumer printNumber) throws InterruptedException {
}
public void printEven(IntConsumer printNumber) throws InterruptedException {
}
public void printOdd(IntConsumer printNumber) throws InterruptedException {
}
} 题目描述
假设有这么一个类
class ZeroAndEvenOdd {
public ZeroAndEvenOdd(int n) { ... } // 构造函数
public void printZero(printNumber) { ... } // 仅打印出 0
public void printEven(printNumber) { ... } // 仅打印出 偶数
public void printOdd(printNumber) { ... } // 仅打印出 奇数
} 相同的一个 ZeroAndEvenOdd类实例将会传递给三个不同的线程:
线程 A 将调用 printZero(),它只输出 0 。
线程 B 将调用 printEven(),它只输出偶数。
线程 C 将调用 printOdd(),它只输出奇数。
每个线程都有一个 printNumber 方法来输出一个整数。请修改给出的代码以输出整数序列 010203040506... ,其中序列的长度必须为 2n。
输入描述
整数n
输出描述
输出整数序列 010203040506... ,输出整数序列 010203040506... ,其中序列的长度必须为 2n
样例输入
5
样例输出
0102030405#爱奇艺##笔试题目##秋招##校招#
