第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

作業(yè)社區(qū)

探索學(xué)習(xí)新天地,共享知識(shí)資源!

0 提交作業(yè)
0個(gè) 布置作業(yè)
0 滿(mǎn)分作業(yè)
得分 100
討論題
得分 100
學(xué)習(xí)任務(wù)

weixin_慕哥3021856 的學(xué)生作業(yè):

epoll.c #include #include #include #include #include #include #include #include #define MAXEVENTS 10 #define FIFO "./fifo_epoll" int main(int argc, const char *argv[]) { int epfd, ret, fd; int rbytes; struct epoll_event eevent; struct epoll_event ret_eev[MAXEVENTS]; char buffer[64] = {0}; epfd = epoll_create(1); if (epfd == -1) { perror("[ERROR] epoll_create()"); exit(EXIT_FAILURE); } printf("epfd = %d\n", epfd); fd = open(FIFO, O_RDONLY | O_NONBLOCK); if (fd == -1) { perror("[ERROR] open()"); exit(EXIT_FAILURE); } eevent.events = EPOLLIN; eevent.data.fd = fd; ret = epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &eevent); if (ret == -1) { perror("[ERROR] epoll_ctl()"); exit(EXIT_FAILURE); } for (;;) { ret = epoll_wait(epfd, ret_eev, MAXEVENTS, 1000); if (ret == -1) { perror("[ERROR] epoll_wait()"); exit(EXIT_FAILURE); } else if (ret == 0) { printf("Timeout\n"); } else { // 循環(huán)處理事件 for (int i = 0; i < ret; i++) { int current_fd = ret_eev[i].data.fd; rbytes = read(current_fd, buffer, sizeof(buffer)-1); if (rbytes > 0) { buffer[rbytes] = '\0'; if (strcmp(buffer, "q") == 0 || strcmp(buffer, "Q") == 0) { close(current_fd); epoll_ctl(epfd, EPOLL_CTL_DEL, current_fd, NULL); printf("The fd[%d] was closed.\n", current_fd); break; } printf("Read buffer: %s\n", buffer); } else if (rbytes == 0) // 寫(xiě)端關(guān)閉 { close(current_fd); epoll_ctl(epfd, EPOLL_CTL_DEL, current_fd, NULL); break; } memset(buffer, 0, sizeof(buffer)); } } } return 0; } namedpipe.c #include #include #include #include #include #include #include #define FIFO "./fifo_epoll" int main(void) { int fd, ret; char wbuf[64]; ssize_t wbytes; memset(wbuf, 0, sizeof(wbuf)); ret = access(FIFO, F_OK); if (ret == -1) { mkfifo(FIFO, 0666); } fd = open(FIFO, O_WRONLY); if (fd == -1) { perror("[ERROR] open()"); exit(EXIT_FAILURE); } for (;;) { printf("Input: "); fgets(wbuf, sizeof(wbuf), stdin); wbuf[strlen(wbuf) - 1] = '\0'; wbytes = write(fd, wbuf, strlen(wbuf)); if (wbytes == -1) { perror("[ERROR] write()"); close(fd); exit(EXIT_FAILURE); } if (strcmp(wbuf, "q") == 0 || strcmp(wbuf, "Q") == 0) { break; } memset(wbuf, 0, sizeof(wbuf)); } close(fd); return 0; }

得分 100
學(xué)習(xí)任務(wù)

慕神4583458 的學(xué)生作業(yè):

#ifndef __JUDGE_H__ #define __JUDGE_H__ #include "Player.hpp" #include "ChessBoard.hpp" class Judge { public: bool isWin(Player *player) { bool ok = false; ok = isHorizontalWin(player->getColor()); if (ok) return true; ok = isVerticalWin(player->getColor()); if (ok) return true; ok = isUphillWin(player->getColor()); if (ok) return true; ok = isDownhillWin(player->getColor()); if (ok) return true; return false; }; bool isHorizontalWin(const string &color) { ChessBoard *chessBoard = ChessBoard::getChessBoard(); int line = chessBoard->getCurrentLine(); int column = chessBoard->getCurrentColumn(); int count = 1; int i; for (i = 1; i < 5; i++) { bool ok = chessBoard->isSameColorChess(color, column + i, line); if (ok) { count++; } else { break; } } if (count >= 5) return true; for (i = 1; i < 5; i++) { bool ok = chessBoard->isSameColorChess(color, column - i, line); if (ok) { count++; } else { break; } } return count >= 5 ? true : false; }; bool isVerticalWin(const string &color) { ChessBoard *chessBoard = ChessBoard::getChessBoard(); int line = chessBoard->getCurrentLine(); int column = chessBoard->getCurrentColumn(); int count = 1; int i; for (i = 1; i < 5; i++) { if (chessBoard->isSameColorChess(color, column, line + i)) { count++; } } if (count >= 5) return true; for (i = 1; i < 5; i++) { if (chessBoard->isSameColorChess(color, column, line - i)) { count++; } } return count >= 5 ? true : false; }; bool isUphillWin(const string &color) { ChessBoard *chessBoard = ChessBoard::getChessBoard(); int line = chessBoard->getCurrentLine(); int column = chessBoard->getCurrentColumn(); int count = 1; int i; for (i = 1; i < 5; i++) { if (chessBoard->isSameColorChess(color, column + i, line - i)) { count++; } } if (count >= 5) return true; for (i = 1; i < 5; i++) { if (chessBoard->isSameColorChess(color, column - i, line + i)) { count++; } } return count >= 5 ? true : false; } bool isDownhillWin(const string &color) { ChessBoard *chessBoard = ChessBoard::getChessBoard(); int line = chessBoard->getCurrentLine(); int column = chessBoard->getCurrentColumn(); int count = 1; int i; for (i = 1; i < 5; i++) { if (chessBoard->isSameColorChess(color, column + i, line + i)) { count++; } } if (count >= 5) return true; for (i = 1; i < 5; i++) { if (chessBoard->isSameColorChess(color, column - i, line - i)) { count++; } } return count >= 5 ? true : false; } }; #endif

得分 100
學(xué)習(xí)任務(wù)

慕神4583458 的學(xué)生作業(yè):

ChessBoard.hpp #ifndef __CHESSBOARD_H__ #define __CHESSBOARD_H__ #include #include "Chess.hpp" using namespace std; #define LINE 15 #define COLUMN 15 #define X_SKIN 4 #define Y_SKIN 2 #define MIN_X 1 #define MAX_X 57 #define MIN_Y 1 #define MAX_Y 29 class ChessBoard { public: ~ChessBoard() { fprintf(stderr, "\033[%d;%dH", MAX_Y + 1, MIN_X); for (int i = 0; i < LINE; i++) { for (int j = 0; j < COLUMN; j++) { if (chess[i][j]) { delete chess[i][j]; } } } } static ChessBoard *getChessBoard(void) { if (!chessBoard) { chessBoard = new ChessBoard; } return chessBoard; }; void show(void) const { FILE *fp; fp = fopen("1_ChessBoard.txt", "r"); if (fp == NULL) { perror("openChessBoard():"); return; } char str[1024]; fprintf(stderr, "\033[%d;%dH", MIN_Y, MIN_X); while(fgets(str, sizeof(str), fp)) { fprintf(stderr, "%s", str); } fclose(fp); }; void placeChess(const Chess *chess) { int y = chess->getY() / Y_SKIN; int x = chess->getX() / X_SKIN; this->chess[y][x] = chess; chess->show(); }; bool isValidPosition(int x, int y) { if (x > MAX_X || y > MAX_Y || x < MIN_X || y < MIN_Y) return false; int line = y / Y_SKIN; int column = x / X_SKIN; return chess[line][column] ? false : true; }; class GC { public: ~GC() { if (chessBoard) { delete chessBoard; } } }; private: ChessBoard() { for (int i = 0; i < LINE; i++) { for (int j = 0; j < COLUMN; j++) { chess[i][j] = NULL; } } }; static ChessBoard *chessBoard; const Chess* chess[LINE][COLUMN]; }; ChessBoard *ChessBoard::chessBoard = nullptr; ChessBoard::GC gc; #endif Player.hpp #ifndef __PLAYER_H__ #define __PLAYER_H__ #include using namespace std; class Player { public: Player(const string &name, const string &color): name(name), color(color) {}; string getName() { return name; }; string getColor() { return color; }; virtual bool placeChess(int x, int y) = 0; private: string name; string color; }; #endif WhitePlayer.hpp #ifndef __WHITEPLAYER_H__ #define __WHITEPLAYER_H__ #include "Player.hpp" #include "ChessBoard.hpp" #include "WhiteChess.hpp" class WhitePlayer: public Player { public: WhitePlayer(const string &name): Player(name, "White") {}; virtual bool placeChess(int x, int y) { ChessBoard *chessBoard = ChessBoard::getChessBoard(); bool ok = chessBoard->isValidPosition(x, y); if (ok) { chessBoard->placeChess(new WhiteChess(x, y)); } return ok; } }; #endif BlackPlayer.hpp #ifndef __BLACKPLAYER_H__ #define __BLACKPLAYER_H__ #include "Player.hpp" #include "ChessBoard.hpp" #include "BlackChess.hpp" class BlackPlayer: public Player { public: BlackPlayer(const string &name): Player(name, "Black") {}; virtual bool placeChess(int x, int y) { ChessBoard *chessBoard = ChessBoard::getChessBoard(); bool ok = chessBoard->isValidPosition(x, y); if (ok) { chessBoard->placeChess(new BlackChess(x, y)); } return ok; } }; #endif main.cpp #include "BlackPlayer.hpp" #include "WhitePlayer.hpp" #include "ChessBoard.hpp" int main() { ChessBoard *chessBoard = ChessBoard::getChessBoard(); chessBoard->show(); WhitePlayer whitePlayer("hqq"); BlackPlayer blackPlayer("pyy"); whitePlayer.placeChess(9, 17); blackPlayer.placeChess(13, 17); } 【圖片】

微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)