“21 天好习惯”第一期-9

目录

leetcode每日一题:

周赛补题:

数据库部分:


leetcode每日一题:

次元门

一道 easy 题 , 暴力模拟.

        将每一行归为一类 , 进行计数 , 最后判断就可以了 .

class Solution {
public:
    vector<string> findWords(vector<string>& words) {
        vector<int>c_nums= {2 , 3 , 3 , 2 , 1 , 2 , 2 , 2 , 1 , 2 , 2 , 2 , 3 , 3 , 1 , 1 , 1 , 1 , 2 , 1 , 1 , 3 , 1 , 3 , 1 , 3};
        vector<string>re;

        for(auto ao : words){
            vector<int>nums(4 , 0);
            for(auto a : ao){
                if(a >= 'a' && a <= 'z') nums[c_nums[a - 'a']] = 1;
                if(a >= 'A' && a <= 'Z') nums[c_nums[a - 'A']] = 1;
            }
            if(nums[1] + nums[2] + nums[3] == 1) re.push_back(ao);
        }

        return re;
    }
};

周赛补题:

次元门

很明显的 bfs 模板题 ( 主要是我想不到别的办法了. 还好数据范围很小 , 所以通过 a.对 val > 1000 和 val < 0. b.重复出现的 val 值. 进行剪枝便可以暴力过去.

        好在数据不大 , 把每次三种计算的结果保存进入队列即可 .

class Solution {
public:
    bool cheak(int num){ return num <= 1000 && num >= 0; }

    int minimumOperations(vector<int>& nums, int start, int goal) {
        queue<pair<int , int>>que;
        que.push({start , 0});
        bitset<1005>bit; bit[start] = 1;

        while(!que.empty()){
            auto [val , ide] = que.front();
            que.pop();

            for(auto ao : nums){
                int num1 = val + ao , num2 = val - ao , num3 = val ^ ao;

                if(num1 == goal || num2 == goal || num3 == goal) return ide + 1;

                if(cheak(num1) && !bit[num1]) bit[num1] = 1 , que.push({num1 , ide + 1}); 
                
                if(cheak(num2) && !bit[num2]) bit[num2] = 1 , que.push({num2 , ide + 1}); 
                
                if(cheak(num3) && !bit[num3]) bit[num3] = 1 , que.push({num3 , ide + 1});
            }
        }

        return -1;
    }
};

数据库部分:

基本查询: 

--1、 查询没有选修课程的学生学号及姓名。

select sno 学号,sname 姓名
from student
where sno not in(
      select b.sno
	  from student b,sc c
	  where b.sno = c.sno
)

--2、查询没有选修“1”号课程的学生姓名。

select sname 学号
from student 
except 
select a.sname 学号
from student a,sc b
where a.sno = b.sno and b.cno = 1

--3、 查询既选修了“数据结构”又选修了“操作系统”的学生姓名。

select a.sname 姓名
from student a,sc b,sc c,course d,course e
where b.cno = d.cno and c.cno = e.cno and b.sno = c.sno and a.sno = b.sno and d.cname = '数据结构' and e.cname = '操作系统' 

--4、查询既选修了“2”号又选修了“4”号课程的学生学号。

select a.sno 学号
from student a,sc b,sc c
where b.sno = c.sno and a.sno = b.sno and b.cno = 2 and c.cno = 4

--5、查询选修了“2”号或“4”号课程的学生学号。

select a.sno 姓名
from student a,sc b
where a.sno = b.sno and b.cno = 2
union 
select a.sno 姓名
from student a,sc b
where a.sno = b.sno and b.cno = 4

--6、查询至少选修了“95002”学生所选课程的学生学号。

select a.sno 学号
from student a
where not exists(
      select *
	  from sc b
	  where b.sno = '95002' and not exists(
	        select *
			from sc c
			where a.sno = c.sno and c.cno = b.cno 
      )
)

--7、查询至少选修了一门其间接先行课为“7”号课程的学生姓名。

select distinct a.sname 姓名
from student a,sc b,course c
where a.sno = b.sno and b.cno = c.cno and cpno = 7

--8、查询选修了所有课程的学生姓名。

select a.sname 姓名
from student a
where not exists( 
      select *
	  from course b
	  where not exists(
	        select *
			from sc c
			where a.sno = c.sno and c.cno = b.cno
      )
)

--9、查询“CS”系的所有学生的学号、姓名、课程名及成绩。

select a.sno 学号,a.sname 姓名,c.cname 课程名,b.grade 成绩
from student a,sc b,course c
where a.sno = b.sno and b.cno = c.cno and a.sdept = 'CS'

--10、查询“CS”系选修课程的成绩在90分以上的所有女生的姓名、课程名和成绩。

select a.sname 姓名,c.cname 课程名,b.grade 成绩
from student a,sc b,course c
where a.sno = b.sno and b.cno = c.cno and a.sdept = 'CS' and b.grade > 90 and a.ssex = '女'

即使明日 天寒地冻 路远马亡.Day Nine -- 行云流水涧.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值