作业社区
探索学习新天地,共享知识资源!
慕运维8597106 的学生作业:
#include int main() { int a[5] = {1,3,5,7,9}; int *p = NULL; int **q = NULL; p = a; q = &p; for(int i = 0;i < sizeof(a) / sizeof(a[0]);i++) { printf("%d ",*(p + i)); } printf("\n"); for(int i = 0;i < sizeof(a) / sizeof(a[0]);i++) { printf("%d ",*(*q + i)); } printf("\n"); return 0; }
+205
胡汉三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
+40
慕运维8597106 的学生作业:
#include int main() { int a[10][10]; for(int i = 0;i < 10;i++) { for(int j = 0;j < i + 1;j++){ if(j == 0 || j == i){ a[i][j] = 1; }else{ a[i][j] = a[i -1][j-1] + a[i - 1][j]; } } } printf("===========================\n"); for(int i = 0;i < 10;i++) { for(int j = 0;j < i + 1;j++) { printf("%d ",a[i][j]); } printf("\n"); } return 0; } 输出结果 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1 1 9 36 84 126 126 84 36 9 1
+197
慕运维8597106 的学生作业:
#include int main() { int sumOdd = 0,sum,avg; int a[8] = {10,15,27,33,78,65}; int len = sizeof(a) / sizeof(a[0]); for(int i = 0; i < len;i++) { printf("%d ",a[i]); sum += a[i]; if(a[i] % 2 == 0) { continue; } sumOdd = sumOdd + a[i]; } printf("\n"); avg = sum / len; printf("sum of odds = %d\n",sumOdd); printf("avg = %d\n",avg); return 0; } 结果 10 15 27 33 78 65 0 0 sum of odds = 140 avg = 28
+206