exam training variant

This commit is contained in:
Kaehvaman 2025-01-20 17:42:23 +04:00
parent 0c32b4dd13
commit 1b2ab06b3a
4 changed files with 99 additions and 37 deletions

View File

@ -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;
}

View File

@ -1,7 +1,6 @@
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <Windows.h>
#include <stdlib.h>
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();

View File

@ -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

View File

@ -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