
作業(yè)社區(qū)
探索學(xué)習(xí)新天地,共享知識(shí)資源!
慕運(yùn)維8597106 的學(xué)生作業(yè):
#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; }





胡漢三66 的學(xué)生作業(yè):
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; // 保存 連續(xù)同色棋子 數(shù) ChessBoard *chessBoard = ChessBoard::getChessBoard(); // 獲取 棋盤指針 int curLine = chessBoard->getCurrentLine(); // 獲取 棋盤 當(dāng)前 行 int curColumn = chessBoard->getCurrentColumn(); // 獲取 棋盤 當(dāng)前 列 for(int i = 0; i < 5; i++){ // 右方向 if(chessBoard->isSameColorChess(chessColor,curLine,curColumn + i)){ // 如果 棋子顏色相同, count++; // 連續(xù)同色棋子數(shù) 加1 }else{ // 如果 棋子顏色不同 break; // 跳出 該for循環(huán) } } if(count >= 5){ // 如果 連續(xù)棋子數(shù) 大于等于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; // 如果同色連子數(shù)滿足5個(gè), 返回true // -1 : 多計(jì)算了一個(gè)棋子 } bool isVerticalWin(const string &chessColor){ // 判斷 棋子顏色 在垂直方向 是否贏了 int count = 0; // 保存 連續(xù)同色棋子 數(shù) ChessBoard *chessBoard = ChessBoard::getChessBoard(); // 獲取 棋盤指針 int curLine = chessBoard->getCurrentLine(); // 獲取 棋盤 當(dāng)前 行 int curColumn = chessBoard->getCurrentColumn(); // 獲取 棋盤 當(dāng)前 列 for(int i = 0; i < 5; i++){ // 向上 if(chessBoard->isSameColorChess(chessColor,curLine - i,curColumn)){ // 如果 棋子顏色相同, count++; // 連續(xù)同色棋子數(shù) 加1 }else{ // 如果 棋子顏色不同 break; // 跳出 該for循環(huán) } } if(count >= 5){ // 如果 連續(xù)棋子數(shù) 大于等于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; // 如果同色連子數(shù)滿足5個(gè), 返回true // -1 : 多計(jì)算了一個(gè)棋子 } bool isUphillWin(const string &chessColor){ // 判斷 棋子顏色 在上坡方向 是否贏了 int count = 0; // 保存 連續(xù)同色棋子 數(shù) ChessBoard *chessBoard = ChessBoard::getChessBoard(); // 獲取 棋盤指針 int curLine = chessBoard->getCurrentLine(); // 獲取 棋盤 當(dāng)前 行 int curColumn = chessBoard->getCurrentColumn(); // 獲取 棋盤 當(dāng)前 列 for(int i = 0; i < 5; i++){ // 右上角方向 if(chessBoard->isSameColorChess(chessColor,curLine - i,curColumn + i)){ // 如果 棋子顏色相同, count++; // 連續(xù)同色棋子數(shù) 加1 }else{ // 如果 棋子顏色不同 break; // 跳出 該for循環(huán) } } if(count >= 5){ // 如果 連續(xù)棋子數(shù) 大于等于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; // 如果同色連子數(shù)滿足5個(gè), 返回true // -1 : 多計(jì)算了一個(gè)棋子 } bool isDownhillWin(const string &chessColor){ // 判斷 棋子顏色 在下坡方向 是否贏了 int count = 0; // 保存 連續(xù)同色棋子 數(shù) ChessBoard *chessBoard = ChessBoard::getChessBoard(); // 獲取 棋盤指針 int curLine = chessBoard->getCurrentLine(); // 獲取 棋盤 當(dāng)前 行 int curColumn = chessBoard->getCurrentColumn(); // 獲取 棋盤 當(dāng)前 列 for(int i = 0; i < 5; i++){ // 右下角方向 if(chessBoard->isSameColorChess(chessColor,curLine + i,curColumn + i)){ // 如果 棋子顏色相同, count++; // 連續(xù)同色棋子數(shù) 加1 }else{ // 如果 棋子顏色不同 break; // 跳出 該for循環(huán) } } if(count >= 5){ // 如果 連續(xù)棋子數(shù) 大于等于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; // 如果同色連子數(shù)滿足5個(gè), 返回true // -1 : 多計(jì)算了一個(gè)棋子 } }; #endif





慕運(yùn)維8597106 的學(xué)生作業(yè):
#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; } 輸出結(jié)果 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




