
作业社区
探索学习新天地,共享知识资源!
慕运维8597106 的学生作业:
#include extern int count_uppercase_character(char* str,int len); int main() { char buf[] = "I Love China"; int ret = count_uppercase_character(buf,strlen(buf)); printf("ret = %d\n",ret); return 0; } int count_uppercase_character(char* str,int len) { int count = 0; for(int i = 0;i < len;i++) { if('A'





慕运维8597106 的学生作业:
#include extern void calc_data(const int num1,const int num2,int *max_value,int *sum); int main() { int a,b,max_value,sum; printf("please input 2 numbers:"); scanf("%d%d",&a,&b); calc_data(a,b,&max_value,&sum); printf("max_value = %d\n",max_value); printf("sum = %d\n",sum); return 0; } void calc_data(int num1,int num2,int *max_value,int *sum) { *max_value = num1 > num2 ? num1 : num2; *sum = num1 + num2; }





慕运维8597106 的学生作业:
#include extern int do_leap(int y); int main() { int year; printf("please input a year:"); scanf("%d",&year); int ret = do_leap(year); if(ret == 1) { printf("%d年是闰年",year); }else{ printf("%d年不是闰年",year); } return 0; } int do_leap(int y) { if(y % 4 == 0 && y % 100 != 0) { return 1; } else if(y % 400 == 0) { return 1; }else { return 0; } }





慕运维8597106 的学生作业:
#include int main() { // 10 20 30 // 40 50 60 int a[2][3] = {10,20,30,40,50,60}; // int (*)[3]; int (*p)[3] = a; // 第一种 for(int i = 0;i < 2;i++) { int * q = *(p + i); for(int j = 0;j < 3;j++) { printf("%d ",*(q+j)); } } printf("\n=========================================================\n"); for(int i = 0;i < 2;i++) { for(int j = 0;j < 3;j++) { printf("%d ",*(a[i] + j)); } } printf("\n=========================================================\n"); for(int i = 0;i < 2;i++) { for(int j = 0;j < 3;j++) { printf("%d ",*(p[i] + j)); } } printf("\n=========================================================\n"); for(int i = 0;i < 2;i++) { for(int j = 0;j < 3;j++) { printf("%d ",*(*(a + i) + j)); } } printf("\n=========================================================\n"); for(int i = 0;i < 2;i++) { for(int j = 0;j < 3;j++) { printf("%d ",*(*(p+i) + j)); } } printf("\n=========================================================\n"); return 0; }





慕运维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; }





胡汉三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





慕运维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




