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. 统计每个月兔子的总数

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

代码实现:

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int count = fib(n);
            System.out.println(count);
        }
    }

    public static int fib(int n) {
        if (n == 1 || n == 2) return 1;
        return fib(n - 1) + fib(n - 2);
    }
}

2. 字符串通配符

代码实现: 

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String t = in.nextLine();// 通配符
            String s = in.nextLine();// 字符串
            System.out.println(match(t, s));
        }
    }


    public static boolean match(String tt, String ss) {
        // 动态规划
        char[] t = tt.toCharArray();
        char[] s = ss.toCharArray();
        // 通配符长度
        int tl = t.length;
        // 字符串长度
        int sl = s.length;
        // 多创建一个是为了避免数组越界
        boolean[][] dp = new boolean[sl + 1][tl + 1];
        // 初始化
        dp[0][0] = true;
        for (int i = 0; i <= sl; i++) {
            for (int j = 1; j <= tl; j++) {
                if (t[j - 1] == '*') {
                    if (i == 0) {
                        dp[i][j] = dp[i][j - 1];
                    } else {
                        if (s[i - 1] == '.'
                                || (s[i - 1] >= 'a' && s[i - 1] <= 'z')
                                || (s[i - 1] >= 'A' && s[i - 1] <= 'A')
                                || ( s[i - 1] >= '0' && s[i - 1] <= '9') ) {
                            dp[i][j] = dp[i][j - 1] || dp[i - 1][j];
                        }
                    }
                } else {
                    // ? 字母数字 . 等
                    if (i > 0 && defs(t[j - 1], s[i - 1])) {
                        dp[i][j] = dp[i - 1][j - 1];
                    }
                }
            }
        }
        return dp[sl][tl];
    }


    public static boolean defs(char t, char s) {
        if (t == '?') return true;
        if (t >= 'a' && t <= 'z') {
            t = (char)(t - 32);
        }
        if (s >= 'a' && s <= 'z') {
            s = (char)(s - 32);
        }
        return s == t;
    }
}

  • 7
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值