为了账号安全,请及时绑定邮箱和手机立即绑定

作业社区

探索学习新天地,共享知识资源!

0 提交作业
0 布置作业
0 满分作业
得分 100
学习任务

工地少年与砖('◡') 的学生作业:

最终效果【图片】 stu_seq.h #ifndef __INT_SEQ_H__ #define __INT_SEQ_H__ #include #define MAX_COUNT 3 // 实际学⽣的存储 typedef struct student { char name[20]; int id; int age; } student; typedef student datatype_t; // 存储学生对象的数组结构 typedef struct seqlist_t { datatype_t* buf[MAX_COUNT]; unsigned int n; } seqlist_t; // 初始化对象 extern seqlist_t* create_empty_seqlist(); // 序列是否已满 bool is_full_seqlist(seqlist_t* l); // 向序列中插入数据 extern void insert_data_seqlist(seqlist_t* l, datatype_t data); // 打印序列中的数据 extern void printf_data_seqlist(const seqlist_t* l); // 判断容器数据是否为空 extern bool is_empty(const seqlist_t* l); // 删除数据 extern void delete_data_seqlist(seqlist_t* l, int id); #endif stu_seq.c #include #include #include #include "stu_seq.h" seqlist_t* create_empty_seqlist() { // c语言中, 可以不用对void*进行强转 seqlist_t* seq = malloc(sizeof(seqlist_t)); if (NULL == seq) { printf("malloc failure \n"); return seq; } memset(seq, 0, sizeof(seqlist_t)); seq->n = 0; return seq; } bool is_full_seqlist(seqlist_t* l) { if (MAX_COUNT == l->n) return true; return false; } void insert_data_seqlist(seqlist_t* l, datatype_t data) { bool res = is_full_seqlist(l); if (res) { printf("容量已满"); return; } datatype_t* tmp = malloc(sizeof(datatype_t)); tmp->id = data.id; strcpy(tmp->name, data.name); tmp->age = data.age; // data是一个值, 不是一个指针, 所以会拷贝它的数据在我们的堆中 l->buf[l->n] = tmp; (l->n)++; } void printf_data_seqlist(const seqlist_t* l) { unsigned int i = 0; for (i = 0; i n; i++) { printf("id = %d, name = %s, age = %d \n", l->buf[i]->id, l->buf[i]->name, l->buf[i]->age); } } bool is_empty(const seqlist_t* l) { if (l->n == 0) { return true; } return false; } bool findTargetIndex(seqlist_t* l, unsigned int* targetIndex, int id) { unsigned int i = 0; for (i = 0; i n; i++) { if (id == l->buf[i]->id) { *targetIndex = i; return true; } } return false; } void delete_data_seqlist(seqlist_t* l, int id) { // sequence delete , after element cover prev element unsigned int targetIndex = 0; // find target index const bool findRes = findTargetIndex(l, &targetIndex, id); if (!findRes) { printf("id不存在, 请检查后重试 \n"); return; } unsigned int index = l->n - 1; seqlist_t* lateFreeData = l->buf[targetIndex]; for (index = l->n - 1; index > targetIndex; index--) { l->buf[index - 1] = l->buf[index]; } l->n--; free(lateFreeData); } main.c #include #include "stu_seq.h" int main(int argc, char const* argv[]) { // 初始化列表 seqlist_t* l = create_empty_seqlist(); unsigned int c = 0; datatype_t stu; for (c = 0; c

得分 100
学习任务

胡汉三66 的学生作业:

Judge.hpp #ifndef _JUDEG_HEAD_H #define _JUDEG_HEAD_H #include "Player.hpp" // 玩家 #include "ChessBoard.hpp" // 棋盘 class Judge{ // 判断类 public: bool isWin(Player *player){ // 判断 玩家 是否赢了 bool ok = false; string chessColor = player->getColor(); // 获取 玩家 棋子颜色 ok = isHorziontalWin(chessColor); // 判断 棋子颜色 在水平方向 是否赢了 if(ok){ return true; } ok = isVerticalWin(chessColor); // 判断 棋子颜色 在垂直方向 是否赢了 if(ok){ return true; } ok = isUphillWin(chessColor); // 判断 棋子颜色 在上坡方向 是否赢了 if(ok){ return true; } ok = isDownhillWin(chessColor); // 判断 棋子颜色 在下坡方向 是否赢了 if(ok){ return true; } return ok; } bool isHorziontalWin(const string &chessColor){ // 判断 棋子颜色 在水平方向 是否赢了 int count = 0; // 保存 连续同色棋子 数 ChessBoard *chessBoard = ChessBoard::getChessBoard(); // 获取 棋盘指针 int curLine = chessBoard->getCurrentLine(); // 获取 棋盘 当前 行 int curColumn = chessBoard->getCurrentColumn(); // 获取 棋盘 当前 列 for(int i = 0; i < 5; i++){ // 右方向 if(chessBoard->isSameColorChess(chessColor,curLine,curColumn + i)){ // 如果 棋子颜色相同, count++; // 连续同色棋子数 加1 }else{ // 如果 棋子颜色不同 break; // 跳出 该for循环 } } if(count >= 5){ // 如果 连续棋子数 大于等于5 return true; // 返回 true } for(int i = 0; i < 5; i++){ // 左方向 if(chessBoard->isSameColorChess(chessColor,curLine,curColumn - i)){ count++; }else{ break; } } return count - 1 >= 5 ? true:false; // 如果同色连子数满足5个, 返回true // -1 : 多计算了一个棋子 } bool isVerticalWin(const string &chessColor){ // 判断 棋子颜色 在垂直方向 是否赢了 int count = 0; // 保存 连续同色棋子 数 ChessBoard *chessBoard = ChessBoard::getChessBoard(); // 获取 棋盘指针 int curLine = chessBoard->getCurrentLine(); // 获取 棋盘 当前 行 int curColumn = chessBoard->getCurrentColumn(); // 获取 棋盘 当前 列 for(int i = 0; i < 5; i++){ // 向上 if(chessBoard->isSameColorChess(chessColor,curLine - i,curColumn)){ // 如果 棋子颜色相同, count++; // 连续同色棋子数 加1 }else{ // 如果 棋子颜色不同 break; // 跳出 该for循环 } } if(count >= 5){ // 如果 连续棋子数 大于等于5 return true; // 返回 true } for(int i = 0; i < 5; i++){ // 向下 if(chessBoard->isSameColorChess(chessColor,curLine + i,curColumn)){ count++; }else{ break; } } return count - 1 >= 5 ? true:false; // 如果同色连子数满足5个, 返回true // -1 : 多计算了一个棋子 } bool isUphillWin(const string &chessColor){ // 判断 棋子颜色 在上坡方向 是否赢了 int count = 0; // 保存 连续同色棋子 数 ChessBoard *chessBoard = ChessBoard::getChessBoard(); // 获取 棋盘指针 int curLine = chessBoard->getCurrentLine(); // 获取 棋盘 当前 行 int curColumn = chessBoard->getCurrentColumn(); // 获取 棋盘 当前 列 for(int i = 0; i < 5; i++){ // 右上角方向 if(chessBoard->isSameColorChess(chessColor,curLine - i,curColumn + i)){ // 如果 棋子颜色相同, count++; // 连续同色棋子数 加1 }else{ // 如果 棋子颜色不同 break; // 跳出 该for循环 } } if(count >= 5){ // 如果 连续棋子数 大于等于5 return true; // 返回 true } for(int i = 0; i < 5; i++){ // 左下角方向 if(chessBoard->isSameColorChess(chessColor,curLine + i,curColumn - i)){ count++; }else{ break; } } return count - 1 >= 5 ? true:false; // 如果同色连子数满足5个, 返回true // -1 : 多计算了一个棋子 } bool isDownhillWin(const string &chessColor){ // 判断 棋子颜色 在下坡方向 是否赢了 int count = 0; // 保存 连续同色棋子 数 ChessBoard *chessBoard = ChessBoard::getChessBoard(); // 获取 棋盘指针 int curLine = chessBoard->getCurrentLine(); // 获取 棋盘 当前 行 int curColumn = chessBoard->getCurrentColumn(); // 获取 棋盘 当前 列 for(int i = 0; i < 5; i++){ // 右下角方向 if(chessBoard->isSameColorChess(chessColor,curLine + i,curColumn + i)){ // 如果 棋子颜色相同, count++; // 连续同色棋子数 加1 }else{ // 如果 棋子颜色不同 break; // 跳出 该for循环 } } if(count >= 5){ // 如果 连续棋子数 大于等于5 return true; // 返回 true } for(int i = 0; i < 5; i++){ // 左上角方向 if(chessBoard->isSameColorChess(chessColor,curLine - i,curColumn + i)){ count++; }else{ break; } } return count - 1 >= 5 ? true:false; // 如果同色连子数满足5个, 返回true // -1 : 多计算了一个棋子 } }; #endif

得分 100
学习任务

工地少年与砖('◡') 的学生作业:

接口 stu_seq.h #ifndef __INT_SEQ_H__ #define __INT_SEQ_H__ #include #define MAX_COUNT 3 // 实际学⽣的存储 typedef struct student { char name[20]; int id; int age; } student; typedef student datatype_t; // 存储学生对象的数组结构 typedef struct seqlist_t { datatype_t *buf[MAX_COUNT]; unsigned int n; } seqlist_t; // 初始化对象 extern seqlist_t *create_empty_seqlist(); // 序列是否已满 const bool is_full_seqlist(seqlist_t *l); // 向序列中插入数据 extern void insert_data_seqlist(seqlist_t *l, datatype_t data); // 打印序列中的数据 extern void printf_data_seqlist(const seqlist_t *l); #endif stu_seq.c 实现 #include "stu_seq.h" #include #include #include seqlist_t *create_empty_seqlist() { // c语言中, 可以不用对void*进行强转 seqlist_t *seq = malloc(sizeof(seqlist_t)); if (NULL == seq) { printf("malloc failure \n"); return seq; } memset(seq, 0, sizeof(seqlist_t)); seq->n = 0; return seq; } bool is_full_seqlist(seqlist_t *l) { if (MAX_COUNT == l->n) return true; return false; } void insert_data_seqlist(seqlist_t *l, datatype_t data) { bool res = is_full_seqlist(l); if (res) { printf("容量已满"); return; } datatype_t *tmp = malloc(sizeof(datatype_t)); tmp->id = data.id; strcpy(tmp->name, data.name); tmp->age = data.age; // data是一个值, 不是一个指针, 所以会拷贝它的数据在我们的堆中 l->buf[l->n] = tmp; (l->n)++; } void printf_data_seqlist(const seqlist_t *l) { unsigned int i = 0; for (i = 0; i n; i++) { printf("id = %d, name = %s, age = %d \n", l->buf[i]->id, l->buf[i]->name, l->buf[i]->age); } } 入口 main.c #include "stu_seq.h" #include int main(int argc, char const *argv[]) { // 初始化列表 seqlist_t *l = create_empty_seqlist(); unsigned int c = 0; datatype_t stu; for (c = 0; c

微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号