当前位置:   article > 正文

48天笔试训练错题——day18

48天笔试训练错题——day18

目录

选择题

1.

2.

3.

4.

5.

编程题

1. 统计每个月兔子的总数

2. 字符串通配符


选择题

1.

count(*) 是一定可以返回数值的,即使表为空,返回的也是 0.

max,t1 中没有数据会返回 null,col1全部都是 null 会返回 null。

concat 字符串拼接的其中一个字符串是 null,那么结果就是 null。

2.

top 是 sql server 中的关键字,用于求前 n 条数据,

语法: select top n 查询字段 from ...

3.

使用函数,就不会使用索引了,函数本身也会消耗时间。

4.

hadoop 是属于大数据方向的数据库。

5.

数据库事务四特性是:原子性,一致性,持续性,隔离性。

编程题

1. 统计每个月兔子的总数

如图,画图之后发现就是斐波那契数,那就直接写即可。

代码实现:

  1. import java.util.Scanner;
  2. // 注意类名必须为 Main, 不要有任何 package xxx 信息
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner in = new Scanner(System.in);
  6. // 注意 hasNext 和 hasNextLine 的区别
  7. while (in.hasNextInt()) { // 注意 while 处理多个 case
  8. int n = in.nextInt();
  9. int count = fib(n);
  10. System.out.println(count);
  11. }
  12. }
  13. public static int fib(int n) {
  14. if (n == 1 || n == 2) return 1;
  15. return fib(n - 1) + fib(n - 2);
  16. }
  17. }

2. 字符串通配符

代码实现: 

  1. import java.util.Scanner;
  2. // 注意类名必须为 Main, 不要有任何 package xxx 信息
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner in = new Scanner(System.in);
  6. // 注意 hasNext 和 hasNextLine 的区别
  7. while (in.hasNextLine()) { // 注意 while 处理多个 case
  8. String t = in.nextLine();// 通配符
  9. String s = in.nextLine();// 字符串
  10. System.out.println(match(t, s));
  11. }
  12. }
  13. public static boolean match(String tt, String ss) {
  14. // 动态规划
  15. char[] t = tt.toCharArray();
  16. char[] s = ss.toCharArray();
  17. // 通配符长度
  18. int tl = t.length;
  19. // 字符串长度
  20. int sl = s.length;
  21. // 多创建一个是为了避免数组越界
  22. boolean[][] dp = new boolean[sl + 1][tl + 1];
  23. // 初始化
  24. dp[0][0] = true;
  25. for (int i = 0; i <= sl; i++) {
  26. for (int j = 1; j <= tl; j++) {
  27. if (t[j - 1] == '*') {
  28. if (i == 0) {
  29. dp[i][j] = dp[i][j - 1];
  30. } else {
  31. if (s[i - 1] == '.'
  32. || (s[i - 1] >= 'a' && s[i - 1] <= 'z')
  33. || (s[i - 1] >= 'A' && s[i - 1] <= 'A')
  34. || ( s[i - 1] >= '0' && s[i - 1] <= '9') ) {
  35. dp[i][j] = dp[i][j - 1] || dp[i - 1][j];
  36. }
  37. }
  38. } else {
  39. // ? 字母数字 . 等
  40. if (i > 0 && defs(t[j - 1], s[i - 1])) {
  41. dp[i][j] = dp[i - 1][j - 1];
  42. }
  43. }
  44. }
  45. }
  46. return dp[sl][tl];
  47. }
  48. public static boolean defs(char t, char s) {
  49. if (t == '?') return true;
  50. if (t >= 'a' && t <= 'z') {
  51. t = (char)(t - 32);
  52. }
  53. if (s >= 'a' && s <= 'z') {
  54. s = (char)(s - 32);
  55. }
  56. return s == t;
  57. }
  58. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/煮酒与君饮/article/detail/864357
推荐阅读
相关标签
  

闽ICP备14008679号