开科唯识笔试

2023-05-16

对于这次的笔试,我只想说BiShi。。。几道编程题加一道SQL题

1.找出所有三位数中的水仙花数

public void getNarcissusNums() {
	int g=0,s=0,b=0,sum=0;
	for(int i=100;i<=999;i++) {
		b=i/100;
		s=(i-b*100)/10;
		g=i-b*100-s*10;
		sum = (int) (Math.pow(b,3)+Math.pow(s,3)+Math.pow(g,3));
		if (sum == i) {
			System.out.println(i);
		}
	}
}

2.输入2,5,计算2+22+222+2222+22222

public int caculate(int a, int b) {
	 /*int sum=0,curr=a;
	 if(b == 1)
		 sum = a;
	 if (b > 1) {
		 sum += a;
		 for(int i=1;i<b;i++) {
			 curr = (int) (a*Math.pow(10, i)+curr);
			 sum += curr;
		 }
	 }
	 System.out.println(sum);
	 return sum;*/
        // 确实上面那方法太复杂了,明明可以简单就实现
	int c = 0, sum = 0;
	for (int n = 1; n <= b; n++) {
		c = (c* 10) + a;
		sum += c;
	}
	System.out.print("sum=" + sum);
	return sum;
}

3.从数组中找出重复元素及其所在位置

public class GetRepeatNums {
	public static void main(String[] args) throws Exception {
        int[] nums = {12, 18, 19, 15, 26, 29, 49, 15, 12, 19, 29, 12, 18};
        // map 的键 为 nums 中的整数,值 为 nums 中整数的位置
        Map<Integer, List<Integer>> map = new LinkedHashMap<>(); // LinkedHashMap 可以维护键值对 加入 map 的顺序

        for (int i = 0; i < nums.length; i++) {
            List<Integer> positions = map.get(nums[i]);

            if (positions == null) { // 如果 map 的键 中不存在这个整数
                positions = new ArrayList<>(1);
                map.put(nums[i], positions); // 将这个整数和与其关联的位置 positions 放入 map
            }

            positions.add(i);
        }
        for (Map.Entry<Integer, List<Integer>> entry : map.entrySet()) {
            List<Integer> positions = entry.getValue();
            if (positions.size() > 1) { // 如果一个整数对应的位置数量大于 1,说明这个整数重复
                int num = entry.getKey();
                printResult(num, positions);
            }
        }
    }

    private static void printResult(int num, List<Integer> positions) {
        StringBuilder result = new StringBuilder();
        result.append(num).append(' ').append('{');
        for (Integer position : positions) {
            result.append(position).append(',');
        }
        result.setCharAt(result.length() - 1, '}'); // 把最后一个 , 替换为 }
        System.out.println(result);
    }

}

4.打印菱形

public class PrintRhombus {
	public static void main(String[] args) {
        print(7); // 输出7行的菱形
    }

    public static void print(int size) {
        if (size % 2 == 0) {
            size++; // 计算菱形大小
        }
        for (int i = 0; i < size / 2 + 1; i++) {
            for (int j = size / 2 + 1; j > i + 1; j--) {
                System.out.print(" "); // 输出左上角位置的空白
            }
            for (int j = 0; j < 2 * i + 1; j++) {

                System.out.print("*"); // 输出菱形上半部边缘

            }
            System.out.println(); // 换行
        }
        for (int i = size / 2 + 1; i < size; i++) {
            for (int j = 0; j < i - size / 2; j++) {
                System.out.print(" "); // 输出菱形左下角空白
            }
            for (int j = 0; j < 2 * size - 1 - 2 * i; j++) {

                System.out.print("*"); // 输出菱形下半部边缘

            }
            System.out.println(); // 换行
        }
    }

}

5.SQL题

CARD 借书卡:          CNO 卡号,NAME 姓名,CLASS 班级
BOOKS 图书:           BNO 书号,BNAME 书名,AUTHOR 作者,PRICE 单价,QUANTITY 库存册数
BORROW 借书记录:  CNO 借书卡号,BNO 书号,RDATE 还书日期
1、找出借书超过5本的读者,输出借书卡号及所借图书册数
select cno,count(*) from borrowgroup by cnohaving count(*)>5;
2、查询当前借了"计算方法"但没有借"计算方法习题集"的读者,输出其借书卡号,并按卡号降序排序输出
select a.cnofrom borrow a,books bwhere a.bno=b.bno and b.bname='计算方法'    
and not exists(select * from borrow aa,books bb 
where aa.bno=bb.bno and bb.bname='计算方法习题集' and aa.cno=a.cno)
order by a.cno desc 
3、将"c01"班同学所借图书的还期都延长一周
update b set rdate=dateadd(day,7,b.rdate)
from card a,borrow b where a.cno=b.cno and a.class='c01' 
4、从books表中删除当前无人借阅的图书记录
delete a from books a where not exists(select * from borrow where bno=a.bno) 
5、如果经常按书名查询图书信息,请建立合适的索引
create index idx_books_bname on books(bname)


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

开科唯识笔试 的相关文章

  • 解决Ubuntu18.04 安装ROS中 sudo rosdep init 和 rosdep update 失败问题

    解决Ubuntu18 04 安装ROS中 sudo rosdep init 和 rosdep update 失败问题 目录 解决Ubuntu18 04 安装ROS中 sudo rosdep init 和 rosdep update 失败问题
  • GD32F303 移植freertos 中断管理设定。。。。

    之前做项目时 xff0c 使用GD32F303并移植了freertos 移植过程网上有很多教程 xff0c 根据这些教程移植就可以 移植完后注意FreeRTOSConfig h中关于RTOS中断管理的设置 我移植时在官网下的是当时最新的RT
  • ros自建功能包操作

    功能包改名 假定功能包原名Apkg xff0c 要改成Bpkg 把Apkg功能包文件夹名改为Bpkg 把CMakeLists txt中project Apkg 改为project Bpkg 把Package xml文件中 lt name g
  • Jacobian矩阵和梯度矩阵

    记号标识 标量 xff1a 常规小写字母 xff1b 向量 xff1a 加粗的小写字母 x 61 x 1
  • 一份还热乎的蚂蚁金服面经(已拿Offer)!附答案!!

    本文转自 xff1a https mp weixin qq com s MzmdxqukOZ6rUta9nkGGw 本文来自我的知识星球的球友投稿 xff0c 他在最近的校招中拿到了蚂蚁金服的实习生Offer xff0c 整体思路和面试题目
  • arduino 自平衡小车3\对mpu6050获得的X轴角度和角速度进行卡尔曼滤波

    对mpu6050获得的X轴角度和角速度进行卡尔曼滤波 mpu6050得到的角度值有些值的偏差较大 xff0c 为了使平衡小车更加稳定 xff0c 需要对获得的角度进行优化 xff0c 使用 卡尔曼滤波 xff0c 代码如下 xff1a in
  • nginx CPU 100 跑满问题定位

    1 确定连接数是不是达到了上限 2 确定是不是开启了gzip压缩 xff0c 确定压缩等级 xff0c 小于1kb的不要压缩 xff1b 图片 xff0c 大文件 xff0c 大压缩文件等不要压缩 3 单个CPU占用100 原因的定位 xf
  • 虚拟串口及其在串口转以太网中的应用

    本文介绍虚拟串口的概念 xff0c 以及如何在串口转以太网中利用该技术 1 虚拟串口的概念 虚拟串口是用操作系统的虚拟驱动技术产生的串口 xff08 COM口 xff09 xff0c 相对于计算机本身的硬件串口 xff08 COM1等 xf
  • 机器学习——PCA降维

    参考文章 xff1a https zhuanlan zhihu com p 77151308 PCA xff08 Principal Component Analysis xff09 是一种常见的数据分析方式 xff0c 常用于高维数据的降
  • C++命名规则--简明即查即用版(Windows开发环境)

    目录 前言 1 类名 2 函数名 3 参数 4 变量 5 常量 6 静态变量 7 全局变量 8 类的成员变量 前言 Microsoft推出的命名规则匈牙利法是 在变量和函数名中加入前缀以增进人们对程序的理解 xff0c 但如此一来太为繁琐
  • STM32中的FreeRTOS-#1(入门)

    写在前面 xff1a 我一直觉得 xff0c 如果我能把一点知识说给别人听 xff0c 并且别人能听懂 xff0c 大概率我自己真的学会了 记录的过程也是自己梳理的过程 xff0c 本系列我把它称为 教程 xff0c 是想把它写得系统且有条
  • 信号量 与 互斥量的区别

    原文来源 https blog csdn net ZhipingXi article details 78031307 信号量 与 互斥量 xff08 锁 xff09 的区别 一 概念和定义 信号量 xff1a 多线程同步使用的 xff1b
  • opencv版本问题,引起的vins视觉结果漂移

    最近在根据vins代码进行改写 xff0c 实验发现 当opencv为3 4 12版本时 xff08 core imgproc imgcodecs这几个库 xff09 xff0c vins 优化结果会非常飘 如果vins结果比较离谱 xff
  • i.MX6U SPI浅析

    1 SPI简介 SPI 全称是 SerialPerripheral Interface xff0c 也就是串行外围设备接口 SPI 是 Motorola 公司推出的一种同步串行接口 技术 xff0c 是一种高速 全双工的同步通信总线 xff
  • 【飞控协议】MavLink介绍和编译

    MavLink是什么 xff1f MavLink xff08 Micro Air Vehicle Link xff0c 微型空中飞行器链路通讯协议 xff09 是在串口通讯基础上的一种更高层的开源通讯协议 xff0c 主要应用在无人飞行器与
  • 工作中常用到的设计模式-调用第三方系统接口

    一 概述 外呼业务场景中 xff0c 有一个关键的接口就是黑名单接口 xff08 包括客户投诉 退订接口 是否还款等 xff09 xff0c 我们系统需要经常去跟外部第三方系统交互 xff08 http方式 xff09 一个请求都会经历这几
  • 多旋翼飞行器振动机理分析和减振设计

    多旋翼飞行器振动机理分析和减振设计 开源资源与pdf版论文见 https gitee com robin shaun Multicopter Vibration Attenuation或 https github com robin sha
  • USB3的端口识别Realsense D435i的USB为USB2的解决办法

    如果确定系统没有问题 xff08 识别其他的设备为USB3 xff09 时 xff0c 可参考如下解决方案 xff0c 来自https www intel com content www us en support articles 000
  • XTDrone无人机仿真平台

    XTDrone无人机仿真平台 背景XTDrone展示 背景 近年来 xff0c 无人机的智能化程度不断提高 xff0c 集群的规模不断增大 xff0c 在这种背景下 xff0c 良好的无人机通用仿真平台的重要性越发凸显 相较于无人车和地面机
  • 栈的Java实现--链栈

    栈的Java实现 链栈 链栈 xff0c 顾名思义 xff0c 就是以链表的形式实现的栈的相关操作 xff0c 其实是功能弱化了的链表 xff0c 如果已经阅读过链表的实现代码 xff0c 那么链栈的实现显得更为容易 链栈的基本结构 xff

随机推荐