Auto commit

This commit is contained in:
2025-03-17 18:51:31 +08:00
9 changed files with 39037 additions and 50 deletions
File diff suppressed because one or more lines are too long
@@ -1,6 +1,6 @@
### 练习一 ### 练习一
**1** ![image-20250315225248590](https://yp.smallkun.cn/markdown/image-20250315225248590.png!compress)
```sql ```sql
#(1) #(1)
@@ -30,7 +30,7 @@ ALTER TABLE customers RENAME TO customers_info;
ALTER TABLE customers_info DROP c_city; ALTER TABLE customers_info DROP c_city;
``` ```
**2** ![image-20250315225304324](https://yp.smallkun.cn/markdown/image-20250315225304324.png!compress)
```sql ```sql
#(1) #(1)
@@ -51,6 +51,10 @@ DROP TABLE orders;
### 练习二 ### 练习二
![image-20250315225318753](https://yp.smallkun.cn/markdown/image-20250315225318753.png!compress)
![image-20250315225328264](https://yp.smallkun.cn/markdown/image-20250315225328264.png!compress)
```sql ```sql
#(1) #(1)
CREATE TABLE pet( CREATE TABLE pet(
@@ -84,8 +88,14 @@ WHERE death IS NOT NULL;
TRUNCATE pet; TRUNCATE pet;
``` ```
---
### 练习三 ### 练习三
![image-20250315225417117](https://yp.smallkun.cn/markdown/image-20250315225417117.png!compress)
![image-20250315225431297](https://yp.smallkun.cn/markdown/image-20250315225431297.png!compress)
```sql ```sql
#1. #1.
CREATE DATABASE test_compay DEFAULT CHARACTER SET utf8; CREATE DATABASE test_compay DEFAULT CHARACTER SET utf8;
@@ -115,24 +125,118 @@ CREATE TABLE salary(
ALTER TABLE salary ADD CONSTRAINT fk_sal_eid FOREIGN KEY(empid) ALTER TABLE salary ADD CONSTRAINT fk_sal_eid FOREIGN KEY(empid)
REFERENCES employee(empid) ON UPDATE CASCADE ON DELETE CASCADE; REFERENCES employee(empid) ON UPDATE CASCADE ON DELETE CASCADE;
#4 #4
INSERT INTO department() INSERT INTO department (depid, depname, deinfo)
VALUES VALUES
(111, '生产部', NULL), (111, '生产部', NULL),
(222, '销售部', NULL), (222, '销售部', NULL),
(333, '人事部', NULL); (333, '人事部', NULL),
(444, '财务部', '负责公司财务管理'),
(555, '技术部', '负责技术研发与支持'),
(666, '市场部', '负责市场推广与品牌建设'),
(777, '客服部', '负责客户服务与支持'),
(888, '采购部', '负责公司物资采购'),
(999, '法务部', '负责公司法律事务'),
(1010, '行政部', '负责公司日常行政管理'),
(1011, '研发部', '负责新产品研发'),
(1012, '培训部', '负责员工培训与发展');
INSERT INTO employee() INSERT INTO employee (empid, name, sex, title, birthday, depid)
VALUES VALUES
(1001, '张三', '', '高级工程师', '1975-1-1', 111), (1001, '张三', '', '高级工程师', '1975-1-1', 111),
(1002, '李四', '', '助工', '1985-1-1', 111), (1002, '李四', '', '助工', '1985-1-1', 111),
(1003, '王五', '', '工程师', '1978-11-11', 222), (1003, '王五', '', '工程师', '1978-11-11', 222),
(1004, '赵六', '', '工程师', '1999-1-1', 222); (1004, '赵六', '', '工程师', '1999-1-1', 222),
(1005, '陈七', '', '会计师', '1980-5-15', 444),
(1006, '刘八', '', '软件工程师', '1990-8-20', 555),
(1007, '孙九', '', '市场经理', '1985-12-25', 666),
(1008, '周十', '', '客服专员', '1992-3-10', 777),
(1009, '吴十一', '', '采购经理', '1988-7-22', 888),
(1010, '郑十二', '', '法务顾问', '1983-9-30', 999),
(1011, '王十三', '', '行政助理', '1995-4-18', 1010),
(1012, '李十四', '', '研发工程师', '1991-11-5', 1011),
(1013, '赵十五', '', '培训讲师', '1987-6-12', 1012),
(1014, '孙十六', '', '技术支持', '1993-2-14', 555),
(1015, '杨十七', '', '销售代表', '1994-8-8', 222);
INSERT INTO salary() INSERT INTO salary (empid, basesalary, titleSalary, decuction)
VALUES VALUES
(1001, 2200, 1100, 200), (1001, 2200, 1100, 200),
(1002, 1200, 200, NULL), (1002, 1200, 200, NULL),
(1003, 2900, 700, 200), (1003, 2900, 700, 200),
(1004, 1950, 700, 150); (1004, 1950, 700, 150),
(1005, 2500, 800, 100),
(1006, 3000, 1200, 250),
(1007, 2800, 1000, 200),
(1008, 1800, 300, 50),
(1009, 3200, 900, 300),
(1010, 3500, 1000, 400),
(1011, 2000, 400, 100),
(1012, 3100, 1100, 200),
(1013, 2700, 800, 150),
(1014, 2300, 700, 100),
(1015, 2600, 600, 200);
```
![image-20250315225441802](https://yp.smallkun.cn/markdown/image-20250315225441802.png!compress)
---
### 练习四
![image-20250315225803115](https://yp.smallkun.cn/markdown/image-20250315225803115.png!compress)
![image-20250315225818026](https://yp.smallkun.cn/markdown/image-20250315225818026.png!compress)
```sql
```
![image-20250315225829272](https://yp.smallkun.cn/markdown/image-20250315225829272.png!compress)
```sql
```
---
### 练习五
![image-20250315230015174](https://yp.smallkun.cn/markdown/image-20250315230015174.png!compress)
```sql
```
![image-20250315230025538](https://yp.smallkun.cn/markdown/image-20250315230025538.png!compress)
```sql
```
---
### 练习六
![image-20250315230057816](https://yp.smallkun.cn/markdown/image-20250315230057816.png!compress)
```sql
```
---
### 练习七
![image-20250315230113710](https://yp.smallkun.cn/markdown/image-20250315230113710.png!compress)
![image-20250315230128412](https://yp.smallkun.cn/markdown/image-20250315230128412.png!compress)
```sql
```
---
### 练习八
![image-20250315230214156](https://yp.smallkun.cn/markdown/image-20250315230214156.png!compress)
![image-20250315230227129](https://yp.smallkun.cn/markdown/image-20250315230227129.png!compress)
```sql
``` ```
+70
View File
@@ -0,0 +1,70 @@
1. **数组求和**
- 编写一个程序,定义一个包含10个整数的数组,计算并输出数组中所有元素的和。
2. **数组最大值和最小值**
- 编写一个程序,定义一个包含10个整数的数组,找到并输出数组中的最大值和最小值。
3. **数组逆序**
- 编写一个程序,定义一个包含10个整数的数组,将数组中的元素逆序存放并输出。
4. **查找元素**
- 编写一个程序,定义一个包含10个整数的数组,输入一个整数,查找该整数是否在数组中。如果存在,输出其位置;否则输出“未找到”。
5. **数组平均值**
- 编写一个程序,定义一个包含10个整数的数组,计算并输出数组中所有元素的平均值。
------
### **中级练习题**
6. **数组排序**
- 编写一个程序,定义一个包含10个整数的数组,使用冒泡排序或选择排序对数组进行升序排序,并输出排序后的数组。
7. **数组去重**
- 编写一个程序,定义一个包含10个整数的数组,去除数组中的重复元素,并输出去重后的数组。
8. **数组合并**
- 编写一个程序,定义两个包含5个整数的数组,将这两个数组合并为一个包含10个整数的数组,并输出合并后的数组。
9. **数组查找第二大值**
- 编写一个程序,定义一个包含10个整数的数组,找到并输出数组中的第二大值。
10. **数组元素统计**
- 编写一个程序,定义一个包含10个整数的数组,统计数组中正数、负数和零的个数,并输出结果。
------
### **高级练习题**
11. **二维数组转置**
- 编写一个程序,定义一个3x3的二维数组,将其转置(行列互换)并输出转置后的数组。
12. **矩阵乘法**
- 编写一个程序,定义两个3x3的二维数组,计算它们的乘积并输出结果矩阵。
13. **数组二分查找**
- 编写一个程序,定义一个已排序的包含10个整数的数组,输入一个整数,使用二分查找算法查找该整数是否在数组中。如果存在,输出其位置;否则输出“未找到”。
14. **数组元素移动**
- 编写一个程序,定义一个包含10个整数的数组,将数组中的所有元素向左移动一位(第一个元素移动到末尾),并输出移动后的数组。
15. **数组子数组和**
- 编写一个程序,定义一个包含10个整数的数组,找到数组中连续子数组的最大和,并输出该和。
------
### **综合练习题**
16. **数组元素频率统计**
- 编写一个程序,定义一个包含10个整数的数组,统计每个元素在数组中出现的次数,并输出结果。
17. **数组元素交换**
- 编写一个程序,定义一个包含10个整数的数组,将数组中的奇数和偶数分开,奇数在前,偶数在后,并输出结果。
18. **数组元素回文判断**
- 编写一个程序,定义一个包含10个整数的数组,判断该数组是否是一个回文数组(即正序和逆序相同),并输出结果。
19. **数组元素模式匹配**
- 编写一个程序,定义一个包含10个整数的数组,输入一个子数组(长度为3),判断该子数组是否在原数组中出现,并输出结果。
20. **数组元素旋转**
- 编写一个程序,定义一个包含10个整数的数组,输入一个整数k,将数组中的元素向右旋转k位,并输出旋转后的数组。
------
### **附加挑战题**
21. **数组元素最大差值**
- 编写一个程序,定义一个包含10个整数的数组,找到数组中两个元素的最大差值(要求较大元素在较小元素之后),并输出结果。
22. **数组元素最长连续序列**
- 编写一个程序,定义一个包含10个整数的数组,找到数组中最长的连续整数序列的长度,并输出结果。
23. **数组元素螺旋遍历**
- 编写一个程序,定义一个3x3的二维数组,按照螺旋顺序遍历数组并输出结果。
24. **数组元素缺失值查找**
- 编写一个程序,定义一个包含n-1个整数的数组,数组中的元素是1到n之间的整数,且没有重复值,找到缺失的那个整数,并输出结果。
25. **数组元素滑动窗口最大值**
- 编写一个程序,定义一个包含10个整数的数组,输入一个整数k(k < 10),找到数组中每个大小为k的滑动窗口的最大值,并输出结果。
+23 -14
View File
@@ -33,29 +33,38 @@ int main(){
```c ```c
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
// 比较函数,用于 qsort
int compare_strings(const void *a, const void *b) {
return strcmp(*(const char **)a, *(const char **)b);
}
int main() { int main() {
char str[100]; // 测试用例:字符串数组
char temp; const char *strings[] = {
int i, j; "banana",
"apple",
"cherry",
"date",
"blueberry"
};
gets(str); // 计算数组的长度
int length = sizeof(strings) / sizeof(strings[0]);
for(i=0;i<strlen(str)-1;i++){ // 使用 qsort 对字符串数组进行排序
for(j=0;j<strlen(str)-1-i;j++){ qsort(strings, length, sizeof(const char *), compare_strings);
if(*(str+j) > *(str+j+1)){
temp = *(str+j); // 输出排序后的字符串数组
*(str+j) = *(str+j+1); printf("Sorted strings:\n");
*(str+j+1) = temp; for (int i = 0; i < length; i++) {
} printf("%s\n", strings[i]);
}
} }
puts(str);
return 0; return 0;
} }
``` ```
### 3. 字符串插入 ### 3. 字符串插入
+23 -14
View File
@@ -1,24 +1,33 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
// 比较函数,用于 qsort
int compare_strings(const void *a, const void *b) {
return strcmp(*(const char **)a, *(const char **)b);
}
int main() { int main() {
char str[100]; // 测试用例:字符串数组
char temp; const char *strings[] = {
int i, j; "banana",
"apple",
"cherry",
"date",
"blueberry"
};
gets(str); // 计算数组的长度
int length = sizeof(strings) / sizeof(strings[0]);
for(i=0;i<strlen(str)-1;i++){ // 使用 qsort 对字符串数组进行排序
for(j=0;j<strlen(str)-1-i;j++){ qsort(strings, length, sizeof(const char *), compare_strings);
if(*(str+j) > *(str+j+1)){
temp = *(str+j); // 输出排序后的字符串数组
*(str+j) = *(str+j+1); printf("Sorted strings:\n");
*(str+j+1) = temp; for (int i = 0; i < length; i++) {
} printf("%s\n", strings[i]);
}
} }
puts(str);
return 0; return 0;
} }
+41
View File
@@ -1,6 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
<<<<<<< HEAD
int main(){ int main(){
char str[100]; char str[100];
char subStr[100]; char subStr[100];
@@ -26,3 +27,43 @@ int main(){
return 0; return 0;
} }
=======
int main() {
char str1[200], str2[100];
int i, j, index;
printf("请输入主字符串:");
fgets(str1, sizeof(str1), stdin);
str1[strcspn(str1, "\n")] = '\0'; // 去除换行符
printf("请输入要插入的字符串:");
fgets(str2, sizeof(str2), stdin);
str2[strcspn(str2, "\n")] = '\0'; // 去除换行符
printf("请输入要插入的位置:");
scanf("%d", &index);
int len1 = strlen(str1);
int len2 = strlen(str2);
// 检查插入位置是否有效
if (index < 0 || index > len1) {
printf("插入位置无效\n");
return 1;
}
// 移动字符以腾出空间
for (i = len1; i >= index; i--) {
str1[i + len2] = str1[i];
}
// 插入 str2
for (j = 0; j < len2; j++) {
str1[index + j] = str2[j];
}
printf("插入后的字符串: %s\n", str1);
return 0;
}
>>>>>>> 1843d42e7e825deacd49772a204a39bc2f132820
+1 -3
View File
@@ -1,3 +1 @@
## 上课笔记归档 ![bef8d22a5447da22e2b0](https://yp.smallkun.cn/markdown/b5d8f50f4cd00fbc6c6db024bb4fb66af047e03b45b239-qzQtTp!compress)
![img](https://yp.smallkun.cn/markdown/image-20250314075859050.png!compress)