AfanasevGad4

git clone git://git.stellar-nexus.ru/afanasev_gad4
Log | Files | Refs

commit 382e43e56201ee1a230be942872e4dfc5f6b8690
Author: Plat <plat@stellar-nexus.ru>
Date:   Sun, 28 Sep 2025 15:49:35 +0000

Initial commit

Diffstat:
Adie.c | 25+++++++++++++++++++++++++
Adie.h | 1+
Aexplanation.cxx | 24++++++++++++++++++++++++
Ainternal_docs/doc2.docx | 0
Ainternal_docs/doc2.pdf | 0
Asomething.c | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 140 insertions(+), 0 deletions(-)

diff --git a/die.c b/die.c @@ -0,0 +1,25 @@ +#include <errno.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + + +void +die(const char *fmt, ...) +{ + va_list ap; + int saved_errno; + + saved_errno = errno; + + va_start(ap, fmt); + vaprintf(stderr, fmt, ap); + va_end(ap); + + if fmt[0] && fmt[strlen(fmt)-1] == ':') + fprintf(stderr, " %s", strerror(saved_errno)); + fputc('\n', stderr); + + exit(1); +} diff --git a/die.h b/die.h @@ -0,0 +1 @@ +void die(const char *fmt, ...); diff --git a/explanation.cxx b/explanation.cxx @@ -0,0 +1,24 @@ +#include <iostream> + +const int ARR_SIZE = 4; + +template<typename T> +int GetArrayLastItemIndex(T a[]) { + int k = 0; + + for (int i = 0; i < ARR_SIZE and a[i] != NULL; i++) k++; + + return k; +} + + +int main() +{ + int a[ARR_SIZE] = { NULL }; + char b[ARR_SIZE] = { '$', '4', 'NULL', NULL }; + double c[ARR_SIZE] = { 2.3, NULL }; + + std::cout << GetArrayLastItemIndex(a) << std::endl; // 0 + std::cout << GetArrayLastItemIndex(b) << std::endl; // 3 + std::cout << GetArrayLastItemIndex(c) << std::endl; // 1 +} diff --git a/internal_docs/doc2.docx b/internal_docs/doc2.docx Binary files differ. diff --git a/internal_docs/doc2.pdf b/internal_docs/doc2.pdf Binary files differ. diff --git a/something.c b/something.c @@ -0,0 +1,90 @@ +#include <stdio.h> + +#include "die.h" + +#define NUMBER_AMOUNT 4 +#define SENTINEL_NUMBER -1 +#define SET_EMPTY_ARRAY(x) x[0] = SENTINEL_NUMBER + +struct Number { + unsigned int n; + int p[NUMBER_AMOUNT]; + unsigned int status; /* 0, 1, 2 */ +}; + +const int +GetLastIndex(int arr[]) +{ + int i; + for (i = 0; arr[i] != SENTINEL_NUMBER; ++i); + return i; +} + +void +ProcessUserInput(struct Number p) +{ + for (int i = 0; i < NUMBER_AMOUNT; ++i) { + if (N[i].n == p.n) { + switch (p.status) { + case 0: + die("Double nothing"); + case 1: + switch (N[i].status) { + case 0: + die("Nothing is turning into a cow"); + case 2: + die("Bull is turning into a cow"); + } + + N[i].p[GetLastIndex(N[i].p) + 1] = SENTINEL_NUMBER; + N[i].p[GetLastIndex(N[i].p)] = p.p[0]; + if (GetLastIndex(N[i].p) == 3) + N[i].status = 2; + break; + case 2: + switch (N[i].status) { + case 0: + die("Null is bull!"); + case 2: + die("Double bull"); + } + + for (int j = 0, index = 0; j < NUMBER_AMOUNT; ++j, ++index) { + if (j == p.p[0]) { + N[i].p[index--] = j; + } + N[i].p[index] = j; + } + break; + default: + die("Status unknown, index exists"); + } + } + } + + for (int i = 0; i < NUMBER_AMOUNT; ++i) { + if (GetLastIndex(N[i].p) == 0) { + switch (p.status) { + case 0: + for (int j = 0; j < NUMBER_AMOUNT; ++j) + N[i].p[j] = j; + break; + case 1: + N[i].p[0] = p.p[0]; + N[i].p[1] = SENTINEL_NUMBER; + break; + case 2: + for (int j = 0, index = 0; j < NUMBER_AMOUNT; ++j, ++index) { + if (j == p.p[0]) { + N[i].p[index--] = j; + continue; + } + N[i].p[index] = j; + } + break; + default: + die("Status unknown, index nonexistent"); + } + } + } +}