2021提前批-科大讯飞、广联达和奇安信-笔试题目解析.md

    29号广联达笔试,GG。
31号科大讯飞笔试,4道题目,AC2.71,
1号奇安信笔试,2道题目,全Ac,
总结以下笔试过程中遇到难题,分享给大家,欢迎来纠正。

笔试题

科大讯飞最坑的一道题目,没有思路,笔试结束后仔细研究,搞明白了。

题目描述:用某种排序方法对关键字序列(25,84,21,47,15,27,68,35,20)进行排序,序列的变化情况采用如下:

输入:25 84 21 47 15 27 68 35 20
输出:15 20 21 25 47 27 68 35 84
15 20 21 25 47 27 68 35 84
15 20 21 25 47 27 68 35 84
15 20 21 25 35 27 47 68 84
15 20 21 25 27 35 47 68 84
15 20 21 25 27 35 47 68 84
解题思路:笔试中未想到思路,快排,归并,简单选择,冒泡和希尔排序都想过,和第一行的输出不一致,导致整个解题没有思路。后来发现这道题是快排,是数据结构书本上的思路限制了我的思想,思维固化。。。首先把它是以第一个元素为基准元素,区别就是交换的时候,基准元素是不和其它元素交换的,只有一轮结束之前确定好位置,再交换。具体可以看代码,一看就明白
代码如下:

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.util.Scanner;

public class test_02_完整版 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] nums = new int[n];
for (int i = 0; i < n; i++) {
nums[i] = sc.nextInt();
}

quicksort(nums, 0, n - 1);
}

public static void quicksort(int[] nums, int left, int right) {
if (left >= right) {
return;
}
int mid = partition(nums, left, right);
print(nums);
quicksort(nums, left, mid - 1);
quicksort(nums, mid + 1, right);
}

public static void print(int[] nums) {
for (int i = 0; i < nums.length; i++) {
System.out.print(nums[i]);
if (i != nums.length - 1) {
System.out.print(" ");
}
}
System.out.println();
}

public static int partition(int[] nums, int left, int right) {
if (left >= right) {
return left;
}
int i = left;
int j = right;
int key = nums[left];
//区别是在这下面
while (i < j) {
while (i < j && nums[j] >= key) {
j--;
}
while (i < j && nums[i] <= key) {
i++;
}
if (i < j) {
int temp = nums[j];
nums[j] = nums[i];
nums[i] = temp;
}
}
nums[left] = nums[i];
nums[i] = key;
return i;
}

}

编程实现一个从字符串输入提取整数的程序,要求尽量多的考虑异常输入的情况。

输入要求:字符串长度大于0
输入:
输入一行字符串为待提取的字符串。
输出:从字符串提取的整数。
input:+1a2
output:12
解题思路:笔试中考虑到了字符串中有换行的情况,但是没有考虑到有负数的情况,导致ac71%。
代码如下:

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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class test_04_完整版 {
/*
* 需要考虑的情况:
* 负数(考虑了去除前导0) 空格 回车
*/
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String lineTxt = "";
String AlartTxt="";
while((lineTxt = bf.readLine()) != null){
lineTxt+='\n';
AlartTxt+=lineTxt;
}
int length = AlartTxt.length();

for(int i=0;i<length;i++) {
char temp = AlartTxt.charAt(i);
//考虑负数的情况
if(temp== '-') {
char nextCh = AlartTxt.charAt(i+1);
if (nextCh!='0' && Character.isDigit(nextCh)) {
System.out.print(temp+nextCh);
i++;
}
continue;
}
if (Character.isDigit(temp)) {
System.out.print(temp);
}
}

}

}

总结

整体表现欠佳,笔试做题状态正在慢慢恢复,科大讯飞提前批笔试没有发挥好,有点遗憾。

坚持原创技术分享,您的支持将鼓励我继续创作!