Auto commit

This commit is contained in:
smallkun 2025-03-22 19:15:32 +08:00
parent 281083bf85
commit 92bbbfb089
7 changed files with 616 additions and 0 deletions

View File

@ -0,0 +1,183 @@
### 试题-1
```c
/*----------------------------------------------------------------------
【程序设计】
------------------------------------------------------------------------
编写一个 C 语言函数,函数接收一个整数数组 arr 以及数组的长度 size 作为参数,使用 bool 类型返回该数组中是否存在重复的元素。在 main 函数中,输入多个正整数(输入非数字字符表示输入结束)并调用该函数,根据返回结果输出相应的提示信息。
示例:
【请输入多个整数输入非数字字符结束输入】1 2 3 4 5 5 6 a
数组中存在重复元素。
------------------------------------------------------------------------
注意:部分源程序给出如下。请勿改动主函数 main 或其它函数中给出的内容,仅在
Program-End之间填入若干语句。
不要删除标志否则不得分。
不要修改或删除Program-End之外的内容否则不得分。
----------------------------------------------------------------------*/
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
bool hasDuplicates(int arr[], int size) {
/**********Program**********/
int i, j;
for(i=0;i<size-1;i++){
for(j=i+1;j<size;j++){
if(arr[i] == arr[j]){
return true;
}
}
}
return false;
/********** End **********/
}
int main() {
int capacity = 10;
int *arr = (int *)malloc(capacity * sizeof(int));
if (arr == NULL) {
printf("内存分配失败!\n");
return 1;
}
int size = 0;
int num;
printf("【请输入多个整数(输入非数字字符结束输入):】");
while (scanf("%d", &num) == 1) {
if (size == capacity) {
capacity *= 2;
arr = (int *)realloc(arr, capacity * sizeof(int));
if (arr == NULL) {
printf("内存分配失败!\n");
return 1;
}
}
arr[size++] = num;
}
while (getchar() != '\n');
if (hasDuplicates(arr, size)) {
printf("数组中存在重复元素。\n");
} else {
printf("数组中不存在重复元素。\n");
}
free(arr);
return 0;
}
```
### 试题-2
```c
/*----------------------------------------------------------------------
【程序设计】
------------------------------------------------------------------------
现在有一位赛车手要驾驶一台电动摩托车去完成多段赛程。这台电动摩托车的电池电量存储
上限是 100 度电哦,它有一个标称的平均电耗,也就是每行驶 100 公里,就会消耗 10度
电。这里有个很重要的前提条件要大家牢记呀,每一段赛程的距离都是小于 600 公里的哦,
并且每次出发的时候,电动摩托车的电池都是充满电的状态呢。还有一个关键的规则得注意
哦,如果电动摩托车到达某个地点之后,赛车手查看发现电池内剩余的电量低于电池总电量
的 10%(也就是 100×10% = 10 度电或者更少啦),那这个时候就必须得在这个地方给电
动摩托车充电了呢,请帮忙计算一下,这名驾驶员在赛程中的哪几段赛程前是需要充电的。
示例1
【请输入赛程段数:】
5
【请输入各段赛程距离,单位公里:】
380 200 390 400 300
【需要在以下几段赛程前充电:】
第 3 段赛程前
第 5 段赛程前
示例2
【请输入赛程段数:】
4
【请输入各段赛程距离,单位公里:】
190 140 110 80
无需充电。
------------------------------------------------------------------------
注意:部分源程序给出如下。请勿改动主函数 main 或其它函数中给出的内容,仅在
Program-End之间填入若干语句。
不要删除标志否则不得分。
不要修改或删除Program-End之外的内容否则不得分。
----------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h> // 引入stdlib.h用于动态内存分配相关操作
#define TANK_CAPACITY 100 // 电池总容量(单位:度)
#define LOW_FUEL_LIMIT (0.10 * TANK_CAPACITY) // 低电量阈值10%
#define AVG_CONSUMPTION_PER_100KM 10 // 平均电耗(单位:度/百公里)
#define FUEL_CONSUMPTION_PER_KM (AVG_CONSUMPTION_PER_100KM / 100.0) // 每公里电耗(单位:度/公里)
int checkRefuelStops(int trips[], int count, int results[]) {
int refuel_count = 0;
double current_fuel = TANK_CAPACITY;
/**********Program**********/
for (int i = 0; i < count; i++) {
if(current_fuel - trips[i]*FUEL_CONSUMPTION_PER_KM <= LOW_FUEL_LIMIT){
results[refuel_count++] = i+1;
current_fuel = TANK_CAPACITY;
}
current_fuel -= trips[i]*FUEL_CONSUMPTION_PER_KM;
}
/********** End **********/
return refuel_count;
}
int main() {
int num_trips;
printf("【请输入赛程段数:】\n");
scanf("%d", &num_trips);
int *trips = (int *)malloc(num_trips * sizeof(int));
if (trips == NULL) {
printf("内存分配失败!\n");
return 1;
}
printf("【请输入各段赛程距离,单位公里:】\n");
for (int i = 0; i < num_trips; ++i) {
scanf("%d", &trips[i]);
}
int *results = (int *)malloc(num_trips * sizeof(int));
if (results == NULL) {
printf("内存分配失败!\n");
free(trips);
return 1;
}
int refuel_count = checkRefuelStops(trips, num_trips, results);
if (refuel_count > 0) {
printf("【需要在以下几段赛程前充电:】\n");
for (int i = 0; i < refuel_count; i++) {
printf("第 %d 段赛程前\n", results[i]);
}
} else {
printf("无需充电。\n");
}
free(trips);
free(results);
return 0;
}
```

View File

@ -0,0 +1,262 @@
### 试题
![数据库题目 (1)](https://yp.smallkun.cn/markdown/%E6%95%B0%E6%8D%AE%E5%BA%93%E9%A2%98%E7%9B%AE%20(1).png!compress)
![数据库题目 (2)](https://yp.smallkun.cn/markdown/%E6%95%B0%E6%8D%AE%E5%BA%93%E9%A2%98%E7%9B%AE%20(2).png!compress)
![数据库题目 (3)](https://yp.smallkun.cn/markdown/%E6%95%B0%E6%8D%AE%E5%BA%93%E9%A2%98%E7%9B%AE%20(3).png!compress)
### 表结构素材
```sql
/*
Navicat MySQL Data Transfer
Source Server : localhost_3306_1
Source Server Type : MySQL
Source Server Version : 50743 (5.7.43-log)
Source Host : localhost:3306
Source Schema : db_sports_meet
Target Server Type : MySQL
Target Server Version : 50743 (5.7.43-log)
File Encoding : 65001
Date: 18/03/2025 15:24:40
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for t_athletes
-- ----------------------------
DROP TABLE IF EXISTS `t_athletes`;
CREATE TABLE `t_athletes` (
`id` int(6) NOT NULL AUTO_INCREMENT,
`name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`sex` enum('男','女') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`birthday` date NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 10051 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of t_athletes
-- ----------------------------
INSERT INTO `t_athletes` VALUES (10001, '余璐', '女', '2001-03-03');
INSERT INTO `t_athletes` VALUES (10002, '向岚', '女', '2000-12-02');
INSERT INTO `t_athletes` VALUES (10003, '郭子韬', '男', '2001-09-17');
INSERT INTO `t_athletes` VALUES (10004, '郝致远', '男', '2000-01-21');
INSERT INTO `t_athletes` VALUES (10005, '史嘉伦', '男', '2000-05-03');
INSERT INTO `t_athletes` VALUES (10006, '高致远', '男', '2002-09-17');
INSERT INTO `t_athletes` VALUES (10007, '史岚', '女', '2001-01-12');
INSERT INTO `t_athletes` VALUES (10008, '邹震南', '男', '2001-12-05');
INSERT INTO `t_athletes` VALUES (10009, '向子异', '男', '1999-09-09');
INSERT INTO `t_athletes` VALUES (10010, '范子异', '男', '2001-09-05');
INSERT INTO `t_athletes` VALUES (10011, '余云熙', '男', '2002-05-26');
INSERT INTO `t_athletes` VALUES (10012, '徐璐', '女', '2001-03-26');
INSERT INTO `t_athletes` VALUES (10013, '方宇宁', '男', '1999-04-18');
INSERT INTO `t_athletes` VALUES (10014, '萧詩涵', '女', '2001-04-09');
INSERT INTO `t_athletes` VALUES (10015, '向致远', '男', '1999-02-14');
INSERT INTO `t_athletes` VALUES (10016, '向岚', '女', '1999-07-31');
INSERT INTO `t_athletes` VALUES (10017, '方安琪', '女', '2000-01-16');
INSERT INTO `t_athletes` VALUES (10018, '刘晓明', '男', '2001-01-17');
INSERT INTO `t_athletes` VALUES (10019, '顾震南', '男', '2000-07-16');
INSERT INTO `t_athletes` VALUES (10020, '汤嘉伦', '男', '2001-12-25');
INSERT INTO `t_athletes` VALUES (10021, '龙睿', '男', '2000-02-14');
INSERT INTO `t_athletes` VALUES (10022, '顾睿', '男', '2001-10-25');
INSERT INTO `t_athletes` VALUES (10023, '卢秀英', '女', '2002-02-24');
INSERT INTO `t_athletes` VALUES (10024, '汪詩涵', '女', '2001-11-27');
INSERT INTO `t_athletes` VALUES (10025, '丁杰宏', '男', '1999-10-05');
INSERT INTO `t_athletes` VALUES (10026, '任安琪', '女', '1999-03-25');
INSERT INTO `t_athletes` VALUES (10027, '沈云熙', '男', '2000-03-21');
INSERT INTO `t_athletes` VALUES (10028, '邵詩涵', '女', '1999-04-04');
INSERT INTO `t_athletes` VALUES (10029, '袁云熙', '男', '2000-04-08');
INSERT INTO `t_athletes` VALUES (10030, '张睿', '男', '1999-12-16');
INSERT INTO `t_athletes` VALUES (10031, '徐杰宏', '男', '2002-01-16');
INSERT INTO `t_athletes` VALUES (10032, '郑云熙', '男', '2002-06-06');
INSERT INTO `t_athletes` VALUES (10033, '梁秀英', '女', '2002-10-27');
INSERT INTO `t_athletes` VALUES (10034, '向晓明', '男', '2002-08-21');
INSERT INTO `t_athletes` VALUES (10035, '江詩涵', '女', '2000-12-16');
INSERT INTO `t_athletes` VALUES (10036, '夏岚', '女', '2002-02-14');
INSERT INTO `t_athletes` VALUES (10037, '程晓明', '男', '2001-09-07');
INSERT INTO `t_athletes` VALUES (10038, '邱云熙', '男', '1999-02-24');
INSERT INTO `t_athletes` VALUES (10039, '曾子韬', '男', '2002-07-07');
INSERT INTO `t_athletes` VALUES (10040, '朱嘉伦', '男', '2000-02-10');
INSERT INTO `t_athletes` VALUES (10041, '魏岚', '女', '2000-02-06');
INSERT INTO `t_athletes` VALUES (10042, '袁云熙', '男', '2000-07-04');
INSERT INTO `t_athletes` VALUES (10043, '田云熙', '男', '2002-12-18');
INSERT INTO `t_athletes` VALUES (10044, '秦嘉伦', '男', '2001-10-29');
INSERT INTO `t_athletes` VALUES (10045, '金秀英', '女', '2001-08-05');
INSERT INTO `t_athletes` VALUES (10046, '高宇宁', '男', '2002-09-24');
INSERT INTO `t_athletes` VALUES (10047, '周宇宁', '男', '2001-10-10');
INSERT INTO `t_athletes` VALUES (10048, '王璐', '女', '2000-09-07');
INSERT INTO `t_athletes` VALUES (10049, '徐致远', '男', '1999-06-09');
INSERT INTO `t_athletes` VALUES (10050, '何云熙', '男', '2001-02-06');
-- ----------------------------
-- Table structure for t_match
-- ----------------------------
DROP TABLE IF EXISTS `t_match`;
CREATE TABLE `t_match` (
`id` int(6) NOT NULL AUTO_INCREMENT,
`sid` int(6) NULL DEFAULT NULL,
`aid` int(6) NULL DEFAULT NULL,
`grade` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 10101 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of t_match
-- ----------------------------
INSERT INTO `t_match` VALUES (10001, 10008, 10014, '第一名');
INSERT INTO `t_match` VALUES (10002, 10003, 10004, '第一名');
INSERT INTO `t_match` VALUES (10003, 10005, 10042, '第二名');
INSERT INTO `t_match` VALUES (10004, 10006, 10037, '第一名');
INSERT INTO `t_match` VALUES (10005, 10003, 10040, '第二名');
INSERT INTO `t_match` VALUES (10006, 10006, 10047, '第十名');
INSERT INTO `t_match` VALUES (10007, 10001, 10002, '第一名');
INSERT INTO `t_match` VALUES (10008, 10006, 10005, '第三名');
INSERT INTO `t_match` VALUES (10009, 10008, 10033, '第六名');
INSERT INTO `t_match` VALUES (10010, 10002, 10026, '第一名');
INSERT INTO `t_match` VALUES (10011, 10006, 10043, '第八名');
INSERT INTO `t_match` VALUES (10012, 10008, 10016, '第七名');
INSERT INTO `t_match` VALUES (10013, 10007, 10017, '第二名');
INSERT INTO `t_match` VALUES (10014, 10002, 10001, '第十一名');
INSERT INTO `t_match` VALUES (10015, 10004, 10006, '第十二名');
INSERT INTO `t_match` VALUES (10016, 10006, 10045, '第七名');
INSERT INTO `t_match` VALUES (10017, 10004, 10013, '第三名');
INSERT INTO `t_match` VALUES (10018, 10008, 10024, '第九名');
INSERT INTO `t_match` VALUES (10019, 10004, 10022, '第四名');
INSERT INTO `t_match` VALUES (10020, 10003, 10046, '第六名');
INSERT INTO `t_match` VALUES (10021, 10008, 10018, '第二名');
INSERT INTO `t_match` VALUES (10022, 10009, 10027, '第九名');
INSERT INTO `t_match` VALUES (10023, 10008, 10030, '第四名');
INSERT INTO `t_match` VALUES (10024, 10004, 10019, '第七名');
INSERT INTO `t_match` VALUES (10025, 10008, 10023, '第八名');
INSERT INTO `t_match` VALUES (10026, 10005, 10041, '第六名');
INSERT INTO `t_match` VALUES (10027, 10009, 10009, '第六名');
INSERT INTO `t_match` VALUES (10028, 10006, 10007, '第六名');
INSERT INTO `t_match` VALUES (10029, 10002, 10050, '第六名');
INSERT INTO `t_match` VALUES (10030, 10004, 10020, '第九名');
INSERT INTO `t_match` VALUES (10031, 10001, 10039, '第十二名');
INSERT INTO `t_match` VALUES (10032, 10008, 10028, '第五名');
INSERT INTO `t_match` VALUES (10033, 10001, 10034, '第七名');
INSERT INTO `t_match` VALUES (10034, 10003, 10015, '第九名');
INSERT INTO `t_match` VALUES (10035, 10002, 10021, '第九名');
INSERT INTO `t_match` VALUES (10036, 10001, 10011, '第二名');
INSERT INTO `t_match` VALUES (10037, 10008, 10010, '第三名');
INSERT INTO `t_match` VALUES (10038, 10006, 10049, '第十一名');
INSERT INTO `t_match` VALUES (10039, 10003, 10031, '第八名');
INSERT INTO `t_match` VALUES (10040, 10007, 10048, '第九名');
INSERT INTO `t_match` VALUES (10041, 10001, 10038, '第十名');
INSERT INTO `t_match` VALUES (10042, 10003, 10036, '第四名');
INSERT INTO `t_match` VALUES (10043, 10009, 10012, '第二名');
INSERT INTO `t_match` VALUES (10044, 10007, 10003, '第一名');
INSERT INTO `t_match` VALUES (10045, 10006, 10044, '第二名');
INSERT INTO `t_match` VALUES (10046, 10005, 10025, '第七名');
INSERT INTO `t_match` VALUES (10047, 10009, 10035, '第十名');
INSERT INTO `t_match` VALUES (10048, 10002, 10008, '第十二名');
INSERT INTO `t_match` VALUES (10049, 10005, 10032, '第八名');
INSERT INTO `t_match` VALUES (10050, 10009, 10029, '第七名');
INSERT INTO `t_match` VALUES (10051, 10004, 10043, '第五名');
INSERT INTO `t_match` VALUES (10052, 10009, 10031, '第三名');
INSERT INTO `t_match` VALUES (10053, 10005, 10029, '第十名');
INSERT INTO `t_match` VALUES (10054, 10006, 10042, '第十二名');
INSERT INTO `t_match` VALUES (10055, 10001, 10012, '第三名');
INSERT INTO `t_match` VALUES (10056, 10007, 10012, '第十名');
INSERT INTO `t_match` VALUES (10057, 10005, 10026, '第十一名');
INSERT INTO `t_match` VALUES (10058, 10003, 10007, '第七名');
INSERT INTO `t_match` VALUES (10059, 10002, 10034, '第二名');
INSERT INTO `t_match` VALUES (10060, 10005, 10005, '第十二名');
INSERT INTO `t_match` VALUES (10061, 10007, 10001, '第七名');
INSERT INTO `t_match` VALUES (10062, 10005, 10038, '第一名');
INSERT INTO `t_match` VALUES (10063, 10007, 10046, '第八名');
INSERT INTO `t_match` VALUES (10064, 10002, 10024, '第十名');
INSERT INTO `t_match` VALUES (10065, 10007, 10049, '第六名');
INSERT INTO `t_match` VALUES (10066, 10005, 10030, '第三名');
INSERT INTO `t_match` VALUES (10067, 10004, 10023, '第一名');
INSERT INTO `t_match` VALUES (10068, 10007, 10044, '第五名');
INSERT INTO `t_match` VALUES (10069, 10001, 10050, '第八名');
INSERT INTO `t_match` VALUES (10070, 10002, 10006, '第七名');
INSERT INTO `t_match` VALUES (10071, 10007, 10014, '第四名');
INSERT INTO `t_match` VALUES (10072, 10002, 10013, '第五名');
INSERT INTO `t_match` VALUES (10073, 10001, 10046, '第十一名');
INSERT INTO `t_match` VALUES (10074, 10003, 10029, '第三名');
INSERT INTO `t_match` VALUES (10075, 10004, 10038, '第二名');
INSERT INTO `t_match` VALUES (10076, 10009, 10008, '第十一名');
INSERT INTO `t_match` VALUES (10077, 10009, 10037, '第五名');
INSERT INTO `t_match` VALUES (10078, 10001, 10006, '第五名');
INSERT INTO `t_match` VALUES (10079, 10009, 10021, '第八名');
INSERT INTO `t_match` VALUES (10080, 10003, 10016, '第五名');
INSERT INTO `t_match` VALUES (10081, 10004, 10025, '第八名');
INSERT INTO `t_match` VALUES (10082, 10001, 10021, '第四名');
INSERT INTO `t_match` VALUES (10083, 10003, 10028, '第十名');
INSERT INTO `t_match` VALUES (10084, 10002, 10003, '第三名');
INSERT INTO `t_match` VALUES (10085, 10002, 10039, '第四名');
INSERT INTO `t_match` VALUES (10086, 10001, 10047, '第六名');
INSERT INTO `t_match` VALUES (10087, 10009, 10033, '第一名');
INSERT INTO `t_match` VALUES (10088, 10004, 10041, '第六名');
INSERT INTO `t_match` VALUES (10089, 10006, 10013, '第九名');
INSERT INTO `t_match` VALUES (10090, 10006, 10004, '第四名');
INSERT INTO `t_match` VALUES (10091, 10002, 10047, '第八名');
INSERT INTO `t_match` VALUES (10092, 10006, 10027, '第五名');
INSERT INTO `t_match` VALUES (10093, 10001, 10018, '第九名');
INSERT INTO `t_match` VALUES (10094, 10007, 10050, '第三名');
INSERT INTO `t_match` VALUES (10095, 10005, 10020, '第四名');
INSERT INTO `t_match` VALUES (10096, 10004, 10007, '第十一名');
INSERT INTO `t_match` VALUES (10097, 10004, 10031, '第十名');
INSERT INTO `t_match` VALUES (10098, 10005, 10033, '第五名');
INSERT INTO `t_match` VALUES (10099, 10009, 10024, '第四名');
INSERT INTO `t_match` VALUES (10100, 10005, 10049, '第九名');
-- ----------------------------
-- Table structure for t_sport
-- ----------------------------
DROP TABLE IF EXISTS `t_sport`;
CREATE TABLE `t_sport` (
`id` int(6) NOT NULL AUTO_INCREMENT,
`name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`time` datetime NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 10010 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of t_sport
-- ----------------------------
INSERT INTO `t_sport` VALUES (10001, '100米跑步', '2023-10-17 09:30:00');
INSERT INTO `t_sport` VALUES (10002, '200米跑步', '2023-10-18 09:30:00');
INSERT INTO `t_sport` VALUES (10003, '800米跑步', '2023-10-17 14:30:00');
INSERT INTO `t_sport` VALUES (10004, '3000米跑步', '2023-10-18 14:30:00');
INSERT INTO `t_sport` VALUES (10005, '跳高', '2023-10-17 10:30:00');
INSERT INTO `t_sport` VALUES (10006, '跳远', '2023-10-17 11:30:00');
INSERT INTO `t_sport` VALUES (10007, '铅球', '2023-10-17 15:30:00');
INSERT INTO `t_sport` VALUES (10008, '110米栏', '2023-10-17 16:30:00');
INSERT INTO `t_sport` VALUES (10009, '跳绳', '2023-10-18 10:30:00');
SET FOREIGN_KEY_CHECKS = 1;
```
### 触发器素材
```sql
CREATE 【 】 assign_judge
【 】 【 】 ON t_sport
FOR EACH ROW
BEGIN
【 】 【 】 t_judge (id, name, tel, sid)
VALUES (1001, '周周', '语文', 【 】);
END
```
### 存储过程素材
```sql
CREATE 【 】 `athlete_grade`(IN 【 】 INT, IN 【 】 INT, 【 】 out_grade VARCHAR(200))
BEGIN
SELECT m.grade 【 】 out_grade
FROM t_match m
WHERE m.aid = 【 】 AND m.sid = 【 】;
END
```

View File

@ -0,0 +1,73 @@
/*----------------------------------------------------------------------
------------------------------------------------------------------------
C arr size 使 bool main
1 2 3 4 5 5 6 a
------------------------------------------------------------------------
main
Program-End之间填入若干语句
Program-End之外的内容否则不得分
----------------------------------------------------------------------*/
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
bool hasDuplicates(int arr[], int size) {
/**********Program**********/
int i, j;
for(i=0;i<size-1;i++){
for(j=i+1;j<size;j++){
if(arr[i] == arr[j]){
return true;
}
}
}
return false;
/********** End **********/
}
int main() {
int capacity = 10;
int *arr = (int *)malloc(capacity * sizeof(int));
if (arr == NULL) {
printf("内存分配失败!\n");
return 1;
}
int size = 0;
int num;
printf("【请输入多个整数(输入非数字字符结束输入):】");
while (scanf("%d", &num) == 1) {
if (size == capacity) {
capacity *= 2;
arr = (int *)realloc(arr, capacity * sizeof(int));
if (arr == NULL) {
printf("内存分配失败!\n");
return 1;
}
}
arr[size++] = num;
}
while (getchar() != '\n');
if (hasDuplicates(arr, size)) {
printf("数组中存在重复元素。\n");
} else {
printf("数组中不存在重复元素。\n");
}
free(arr);
return 0;
}

View File

@ -0,0 +1,98 @@
/*----------------------------------------------------------------------
------------------------------------------------------------------------
100 100 10
600
10% 100×10% = 10
1
5
380 200 390 400 300
3
5
2
4
190 140 110 80
------------------------------------------------------------------------
main
Program-End之间填入若干语句
Program-End之外的内容否则不得分
----------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h> // 引入stdlib.h用于动态内存分配相关操作
#define TANK_CAPACITY 100 // 电池总容量(单位:度)
#define LOW_FUEL_LIMIT (0.10 * TANK_CAPACITY) // 低电量阈值10%
#define AVG_CONSUMPTION_PER_100KM 10 // 平均电耗(单位:度/百公里)
#define FUEL_CONSUMPTION_PER_KM (AVG_CONSUMPTION_PER_100KM / 100.0) // 每公里电耗(单位:度/公里)
int checkRefuelStops(int trips[], int count, int results[]) {
int refuel_count = 0;
double current_fuel = TANK_CAPACITY;
/**********Program**********/
for (int i = 0; i < count; i++) {
if(current_fuel - trips[i]*FUEL_CONSUMPTION_PER_KM <= LOW_FUEL_LIMIT){
results[refuel_count++] = i+1;
current_fuel = TANK_CAPACITY;
}
current_fuel -= trips[i]*FUEL_CONSUMPTION_PER_KM;
}
/********** End **********/
return refuel_count;
}
int main() {
int num_trips;
printf("【请输入赛程段数:】\n");
scanf("%d", &num_trips);
int *trips = (int *)malloc(num_trips * sizeof(int));
if (trips == NULL) {
printf("内存分配失败!\n");
return 1;
}
printf("【请输入各段赛程距离,单位公里:】\n");
for (int i = 0; i < num_trips; ++i) {
scanf("%d", &trips[i]);
}
int *results = (int *)malloc(num_trips * sizeof(int));
if (results == NULL) {
printf("内存分配失败!\n");
free(trips);
return 1;
}
int refuel_count = checkRefuelStops(trips, num_trips, results);
if (refuel_count > 0) {
printf("【需要在以下几段赛程前充电:】\n");
for (int i = 0; i < refuel_count; i++) {
printf("第 %d 段赛程前\n", results[i]);
}
} else {
printf("无需充电。\n");
}
free(trips);
free(results);
return 0;
}