From 1b2ab06b3aeb94cc39f577f53a0efeea15fc7f9a Mon Sep 17 00:00:00 2001 From: Kaehvaman Date: Mon, 20 Jan 2025 17:42:23 +0400 Subject: [PATCH] exam training variant --- Game of Life/src/main.c | 64 ++++++++++++++----- exam test variant/exam test variant/main.c | 60 +++++++++++------ exam test variant/exam test variant/out.txt | 2 +- exam test variant/exam test variant/test1.txt | 10 +++ 4 files changed, 99 insertions(+), 37 deletions(-) create mode 100644 exam test variant/exam test variant/test1.txt diff --git a/Game of Life/src/main.c b/Game of Life/src/main.c index deb1b9a..44f4704 100644 --- a/Game of Life/src/main.c +++ b/Game of Life/src/main.c @@ -13,9 +13,9 @@ #include "dynamic_memory.h" #include "memory_arena.h" -#define MAP_X 1200 -#define MAP_Y 600 -#define CELL_SIZE 2 +#define MAP_X 100 +#define MAP_Y 100 +#define CELL_SIZE 10 #define FCELL_SIZE (float)CELL_SIZE #define BOTTOM_BAR_HEIGHT 60 @@ -74,22 +74,24 @@ static inline single_gol(int x, int y) } } + + int gol_thread(void* arg_ptr) { golArgs args = *(golArgs*)(arg_ptr); - for (int x = args.startX; x < args.endX; x++) { - for (int y = args.startY; y < args.endY; y++) { + for (int x = args.startX + 1; x < args.endX - 1; x++) { + for (int y = args.startY + 1; y < args.endY - 1; y++) { int neighbours = 0; - neighbours += checkCell(x - 1, y); - neighbours += checkCell(x - 1, y + 1); - neighbours += checkCell(x - 1, y - 1); - neighbours += checkCell(x + 1, y); - neighbours += checkCell(x + 1, y + 1); - neighbours += checkCell(x + 1, y - 1); - neighbours += checkCell(x, y + 1); - neighbours += checkCell(x, y - 1); + neighbours += map[x - 1][y]; + neighbours += map[x - 1][y + 1]; + neighbours += map[x - 1][y - 1]; + neighbours += map[x + 1][y]; + neighbours += map[x + 1][y + 1]; + neighbours += map[x + 1][y - 1]; + neighbours += map[x][y + 1]; + neighbours += map[x][y - 1]; if (neighbours == 2) { tempMap[x][y] = map[x][y]; @@ -104,10 +106,38 @@ int gol_thread(void* arg_ptr) } } - single_gol(args.startX, args.startY); - single_gol(args.startX, args.endY); - single_gol(args.endX, args.startY); - single_gol(args.endX, args.endY); + for (int x = args.startX; x < args.endX; x++) { + int neighbours = 0; + + neighbours += map[x - 1][y]; + neighbours += map[x - 1][y + 1]; + neighbours += map[x - 1][y - 1]; + neighbours += map[x + 1][y]; + neighbours += map[x + 1][y + 1]; + neighbours += map[x + 1][y - 1]; + neighbours += map[x][y + 1]; + neighbours += map[x][y - 1]; + + if (neighbours == 2) { + tempMap[x][y] = map[x][y]; + } + else if (neighbours == 3) { + tempMap[x][y] = true; + } + else { + tempMap[x][y] = false; + } + } + for (int x = args.startX; x < args.endX; x++) { + + } + for (int y = args.startY; y < args.endY; y++) { + + } + for (int y = args.startY; y < args.endY; y++) { + + } + return 0; } diff --git a/exam test variant/exam test variant/main.c b/exam test variant/exam test variant/main.c index 8c346fa..b70aaed 100644 --- a/exam test variant/exam test variant/main.c +++ b/exam test variant/exam test variant/main.c @@ -1,7 +1,6 @@ #define _CRT_SECURE_NO_WARNINGS #include #include -#include int N1; int N2; @@ -122,6 +121,45 @@ void deleteRow(int row) N2 -= 1; } +void addRow() { + if (N2 + 1 <= MAX_N2) { + for (int m = 0; m < M2; m++) { + A2[N2][m] = 0; + } + N2++; + } + else { + printf("Достигнут максимум строк!\n"); + } +} + +void insertRow(int row) { + if (N2 + 1 <= MAX_N2) { + for (int n = N2; n > row; n--) { + for (int m = 0; m < M2; m++) { + A2[n][m] = A2[n - 1][m]; + } + } + for (int m = 0; m < M2; m++) { + A2[row][m] = 0; + } + N2++; + } + else { + printf("Достигнут максимум строк!\n"); + } +} + +void deleteColumn(int column) +{ + for (int n = 0; n < N2; n++) { + for (int m = column; m < M2 - 1; m++) { + A2[n][m] = A2[n][m + 1]; + } + } + M2 -= 1; +} + void addColumn() { if (M2 + 1 <= MAX_M2) { for (int n = 0; n < N2; n++) { @@ -151,28 +189,12 @@ void insertColumn(int column) { } } -void insertRow(int row) { - if (N2 + 1 <= MAX_N2) { - for (int n = N2; n > row; n--) { - for (int m = 0; m < M2; m++) { - A2[n][m] = A2[n - 1][m]; - } - } - for (int m = 0; m < M2; m++) { - A2[row][m] = 0; - } - N2++; - } - else { - printf("Достигнут максимум строк!\n"); - } -} - void task3() { for (int n = 0; n < N2; n++) { for (int m = 0; m < M2; m++) { if (A2[n][m] < 0) { deleteRow(n); + n--; break; } } @@ -185,7 +207,7 @@ int main() SetConsoleCP(1251); SetConsoleOutputCP(1251); - loadLists("test.txt"); + loadLists("test1.txt"); printLists(); task2(); diff --git a/exam test variant/exam test variant/out.txt b/exam test variant/exam test variant/out.txt index 95f0dcc..65a0b5c 100644 --- a/exam test variant/exam test variant/out.txt +++ b/exam test variant/exam test variant/out.txt @@ -1,5 +1,5 @@ 6 1 2 104 106 7 8 2 4 --2 -1 0 1 +6 4 5 1 2 3 4 3 diff --git a/exam test variant/exam test variant/test1.txt b/exam test variant/exam test variant/test1.txt new file mode 100644 index 0000000..bdc8364 --- /dev/null +++ b/exam test variant/exam test variant/test1.txt @@ -0,0 +1,10 @@ +6 +1 2 4 6 7 8 +7 4 +-2 -1 0 1 +3 4 -5 6 +6 4 5 1 +10 -1 0 1 +2 3 4 3 +2 1 0 -1 +5 -6 7 -8 \ No newline at end of file