笔试强训(十七)

news/2024/7/8 2:43:42

目录

  • 一、选择题
  • 二、编程题
    • 2.1 杨辉三角的变形
      • 2.1.1 题目
      • 2.1.2 题解
    • 2.2 计算字符出现的次数
      • 2.2.1 题目
      • 2.2.2 题解

一、选择题

(1)下列SQL语句中哪条语句可为用户zhangsan分配数据库userdb表userinfo的查询和插入数据权限(A)
A.grant select,insert on userdb.userinfo to ‘zhangsan’@‘localhost’
B.grant ‘zhangsan’@‘localhost’ to select,insert for userdb.userinfo
C.grant select,insert on userdb.userinfo for ‘zhangsan’@‘localhost’
D.grant ‘zhangsan’@‘localhost’ to userdb.userinfo on select,insert

常用的管理权限命令有:
授予用户某张表查询/插入/修改/删除数据的权限:
grant select/insert/update/delete on 数据库名.表名 to 用户名@‘该用户允许访问的ip’

(2)下列关于数据库索引的说法错误的是(B)
A.索引可以提升查询、分组和排序的性能
B.索引不会影响表的更新、插入和删除操作的效率
C.全表扫描不一定比使用索引的执行效率低
D.对于只有很少数据值的列,不应该创建索引

数据量越大,数据更新的操作(插入、修改和删除)对索引的效率影响越大,需要对B+树进行调整

(3)下面哪个SQL命令用来向表中添加列(D)
A.modify table tablename add column colomuName
B.modify table tablename add colomuName
C.alter table tablename add column colomuName
D.alter table tablename add columnName type

修改表结构的关键字都是alter table 表名,再根根据的修改语句

(4)有订单表orders,包含字段用户信息userid,字段产品信息productid,以下语句能返回至少被订购过两次的productid(D)
A.select productid from orders where count(productid)>1
B.select productid from orders where max(productid)>1
C.select productid from orders where having count(productid)>1 group by productid
D.select productid from orders where group by productid having count(productid)>1

(5)在手机开发中常用的数据库是(A)
A.sqlLite
B.Oracle
C.Sql Server

二、编程题

2.1 杨辉三角的变形

2.1.1 题目

在这里插入图片描述

2.1.2 题解

思路多写几行后找规律
在这里插入图片描述
代码:

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
       Scanner scanner=new Scanner(System.in);
       int n=scanner.nextInt();
       if(n<3){
           System.out.println(-1);
       }else if(n%2==1){
           System.out.println(2);
       }else if(n%4==0){
           System.out.println(3);
       }else if(n%4==2){
           System.out.println(4);
       }
    }
}

【常规做法】:按照题目意思,可以发现第n行有2n - 1个元素,第i,j元素等于上一行第j - 2,j - 1,j三列元素之和,每一行的第一列和最后一列都为1,如果是第二列,则只是两个元素之和

代码:

 public static void main(String[] args) {
       Scanner scanner=new Scanner(System.in);
       int n=scanner.nextInt();
       int[][] a=new int[n][2*n-1];
        a[0][0]=1;
        for(int i=1;i<n;i++){
            a[i][0]=a[i][2*i]=1;
            for(int j=1;j<2*n-1;j++){
               if(j==1){
                   a[i][j]=a[i-1][j]+a[i-1][j-1];
               }else {
                   a[i][j]=a[i-1][j]+a[i-1][j-1]+a[i-1][j-2];
               }
            }
        }
        int j=0;
        for(j=0;j<2*n-1;j++){
            if(a[n-1][j]%2==0){
                System.out.println(j+1);
                break;
            }
        }
        if(j==2*n-1){
            System.out.println(-1);
        }
    }

但这种方法会造成堆内存不够
在这里插入图片描述

2.2 计算字符出现的次数

2.2.1 题目

在这里插入图片描述

2.2.2 题解

思路:核心方法,equalsIgnoreCase(),遍历str1字符串中的每个字符,看是否和字符str2相等,若相等,count++

代码:

public static void main(String[] args)  {
        Scanner scanner=new Scanner(System.in);
        String str1= scanner.nextLine();
        String str2=scanner.nextLine();
        char[] s=str1.toCharArray();
        int count=0;
         for(int i=0;i<str1.length();i++){
             if(str2.equalsIgnoreCase(String.valueOf(s[i]))){
            count++;
             }
         }
        System.out.println(count);
    }

【equalsIgnoreCase()方法说明】
在这里插入图片描述


http://lihuaxi.xjx100.cn/news/58074.html

相关文章

Linux学习 -- Shell学习之条件判断

常用的判断条件if判断case判断 一、常用的判断条件 1、基本语法 [ condition ]&#xff08;注意condition前后要有空格&#xff09;。 注意:条件非空即为 true&#xff0c;[ atguigu ]返回true&#xff0c;[返回false。 2&#xff0e;常用判断条件。 (1)两个整数之间比…

ASP.NET Core--配置文件

文章目录配置文件添加配置文件读取配置文件控制台读取配置文件**控制器中读取对象读取自定义配置文件多环境配置文件配置文件 添加配置文件 在项目目录下有个 appsettings.json &#xff0c;我们先来操作这个文件。 在appsettings.json 添加如下两个节点。 {"Data&quo…

2022-10-04 语法分析器bison说明

https://www.gnu.org/software/bison/manual/bison.html 参考: https://blog.csdn.net/weixin_44705391/article/details/115555161 https://zhuanlan.zhihu.com/p/52326306 https://zhuanlan.zhihu.com/p/120812270 https://zhuanlan.zhihu.com/p/89479111 说明: Unix Le…

【问题解决】大佬亲授的姿势——PlatformIO生成bin文件方法

微信关注公众号 “DLGG创客DIY”设为“星标”&#xff0c;重磅干货&#xff0c;第一时间送达。最近写创客项目程序基本都用PlatformIO&#xff08;以后简称PIO&#xff09;&#xff0c;PIO在很多方面都优于arduino IDE&#xff0c;今天就不展开了啊&#xff0c;回头专门起一篇文…

【蓝桥杯真题练习】STEMA科技素养练习题库 答案版004 持续更新中~

1、在一个圆形的桌子上,甲和乙轮流摆放硬币。规则是每次每人摆一个,硬币不能互相重叠, 也不能有一部分在桌面边缘之外。若轮到一方摆放硬币时找不到地方摆放,则另一方获胜。假如甲第一个摆放硬币,那么( ) A 甲必胜 B 乙必胜 C 会平局 D 条件不足无法判断 答案:A…

基于PHP的公共课考勤管理系统设计与实现

目录 第一章 概 述 5 第二章 系统的需求分析 10 2.1 系统需求分析 10 1&#xff0e;任务概述 10 2.功能需求 10 2.2 总体设计 11 1&#xff0e;本课题研究的内容 11 2&#xff0e;此系统共分为六个较大的模块&#xff1a; 11 表2 教师信息表&#xff08;t_infor&#xff09; 17…

分类算法学习(python)

数据集 调用方式&#xff1a;load_xxxx() 鸢尾花数据集150*4 load_iris() 手写数字load_digits() fetch_xxx() 路透社新闻语料数据集fetch_rev1() (较大的数据集) 实例&#xff1a; #各类信息与房价from sklearn.datasets import load_boston bostonload_boston() print(boston…

ViewModel的基本用法

本来想弄个游戏开始的倒计时&#xff0c;结果用普通方法没弄出来&#xff0c;后来发现需要用LifeCirle可以对页面进行实时更新。于是找了相关教材。 package com.example.myapplication;import androidx.appcompat.app.AppCompatActivity; import androidx.lifecycle.ViewMode…