From 6ffe18f36a51ae13d488f600ff8ee19347f0ce3a Mon Sep 17 00:00:00 2001 From: AZEN-SGG Date: Sun, 11 May 2025 14:38:39 +0300 Subject: [PATCH] making dist --- 2025.02.21/Makefile | 14 - 2025.02.21/a01.c | 63 ----- 2025.02.21/a02.c | 63 ----- 2025.02.21/a03.c | 63 ----- 2025.02.21/a04.c | 63 ----- 2025.02.21/a05.c | 63 ----- 2025.02.21/a06.c | 63 ----- 2025.02.21/a07.c | 63 ----- 2025.02.21/a08.c | 63 ----- 2025.02.21/array.c | 66 ----- 2025.02.21/array.h | 15 -- 2025.02.21/io_status.h | 12 - 2025.02.21/solve.c | 269 -------------------- 2025.02.21/solve.h | 27 -- 2025.05.02/06Ex/comp.h | 2 +- 2025.05.02/06Ex/solve.c | 31 ++- 2025.05.02/10Ex/Makefile | 42 +++ 2025.05.02/10Ex/init_f.c | 61 +++++ 2025.05.02/10Ex/init_f.h | 13 + 2025.05.02/10Ex/main.c | 49 ++++ 2025.05.02/10Ex/solve.c | 74 ++++++ 2025.05.02/10Ex/solve.h | 56 ++++ 2025.05.02/dist/Krivoruchenko_SK/a05.c | 49 ++++ 2025.05.02/dist/Krivoruchenko_SK/a06.c | 66 +++++ 2025.05.02/dist/Krivoruchenko_SK/array_io.c | 41 +++ 2025.05.02/dist/Krivoruchenko_SK/array_io.h | 11 + 2025.05.02/dist/Krivoruchenko_SK/comp.h | 50 ++++ 2025.05.02/dist/Krivoruchenko_SK/init_f.c | 104 ++------ 2025.05.02/dist/Krivoruchenko_SK/polynom.c | 43 ++++ 2025.05.02/dist/Krivoruchenko_SK/polynom.h | 6 + 2025.05.02/tests/6th_test.sh | 30 ++- 2025.05.02/tests/main_test.sh | 12 +- 32 files changed, 630 insertions(+), 1017 deletions(-) delete mode 100644 2025.02.21/Makefile delete mode 100644 2025.02.21/a01.c delete mode 100644 2025.02.21/a02.c delete mode 100644 2025.02.21/a03.c delete mode 100644 2025.02.21/a04.c delete mode 100644 2025.02.21/a05.c delete mode 100644 2025.02.21/a06.c delete mode 100644 2025.02.21/a07.c delete mode 100644 2025.02.21/a08.c delete mode 100644 2025.02.21/array.c delete mode 100644 2025.02.21/array.h delete mode 100644 2025.02.21/io_status.h delete mode 100644 2025.02.21/solve.c delete mode 100644 2025.02.21/solve.h create mode 100644 2025.05.02/10Ex/Makefile create mode 100644 2025.05.02/10Ex/init_f.c create mode 100644 2025.05.02/10Ex/init_f.h create mode 100644 2025.05.02/10Ex/main.c create mode 100644 2025.05.02/10Ex/solve.c create mode 100644 2025.05.02/10Ex/solve.h create mode 100644 2025.05.02/dist/Krivoruchenko_SK/a05.c create mode 100644 2025.05.02/dist/Krivoruchenko_SK/a06.c create mode 100644 2025.05.02/dist/Krivoruchenko_SK/array_io.c create mode 100644 2025.05.02/dist/Krivoruchenko_SK/array_io.h create mode 100644 2025.05.02/dist/Krivoruchenko_SK/comp.h create mode 100644 2025.05.02/dist/Krivoruchenko_SK/polynom.c create mode 100644 2025.05.02/dist/Krivoruchenko_SK/polynom.h diff --git a/2025.02.21/Makefile b/2025.02.21/Makefile deleted file mode 100644 index 8050f29..0000000 --- a/2025.02.21/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -FLAGS = -fstack-protector-all -W -Wall -Wextra -Wunused -Wcast-align -Werror -pedantic -pedantic-errors -Wfloat-equal -Wpointer-arith -Wformat-security -Wmissing-format-attribute -Wformat=1 -Wwrite-strings -Wcast-align -Wno-long-long -std=gnu99 -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wold-style-definition -Wdeclaration-after-statement -Wbad-function-cast -Wnested-externs -O3 - -%.out: %.o solve.o array.o - gcc $(FLAGS) $^ -o $@ -%.o: %.c - gcc -c $(FLAGS) $< - -all: a01.out a02.out a03.out a04.out a05.out a06.out a07.out a08.out - -solve.o: solve.c solve.h -array.o: array.c array.h - -clean: - rm -f *.o *.out diff --git a/2025.02.21/a01.c b/2025.02.21/a01.c deleted file mode 100644 index e0e5ea6..0000000 --- a/2025.02.21/a01.c +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include - -#include "io_status.h" -#include "array.h" -#include "solve.h" - -int main(int argc, char * argv[]) { - int task = 1; - int n = 0, m = 0; - char * name = 0; - char * s = 0; - char ** a = 0; - io_status ret; - double t; - - if (!(argc == 5 && sscanf(argv[1], "%d", &n) == 1 && sscanf(argv[2], "%d", &m) == 1)) - { - printf("Usage: %s n m file string\n", argv[0]); - return 1; - } - name = argv[3]; - s = argv[4]; - a = (char **)malloc(n * sizeof(char **)); - if (!a) - { - printf("Can not allocate array len %d\n", n); - return ERROR_MEM; - } - ret = read_array(a, n, name); - do { - switch (ret) { - case SUCCESS: - continue; - case ERROR_OPEN: - printf("Can not open %s\n", name); - break; - case ERROR_READ: - printf("Can not read %s\n", name); - break; - case ERROR_MEM: - printf("Not enough memory\n"); - break; - } - - free(a); - return 3; - } while (0); - - print_array(a, n, m); - t = clock(); - ret = t1_solve(a, n, s); - t = (clock() - t); - printf("New array:\n"); - print_array(a, ret, m); - printf("%s : Task = %d Result = %d Elapsed = %.2f\n", - argv[0], task, ret, t); - free_array(a, ret); - free(a); - a = 0; - return 0; -} diff --git a/2025.02.21/a02.c b/2025.02.21/a02.c deleted file mode 100644 index e73740f..0000000 --- a/2025.02.21/a02.c +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include - -#include "io_status.h" -#include "array.h" -#include "solve.h" - -int main(int argc, char * argv[]) { - int task = 2; - int n = 0, m = 0; - char * name = 0; - char * s = 0; - char ** a = 0; - io_status res; - double t; - - if (!(argc == 5 && sscanf(argv[1], "%d", &n) == 1 && sscanf(argv[2], "%d", &m) == 1)) - { - printf("Usage: %s n m file string\n", argv[0]); - return 1; - } - name = argv[3]; - s = argv[4]; - a = (char **)malloc(n * sizeof(char **)); - if (!a) - { - printf("Can not allocate array len %d\n", n); - return ERROR_MEM; - } - res = read_array(a, n, name); - do { - switch (res) { - case SUCCESS: - continue; - case ERROR_OPEN: - printf("Can not open %s\n", name); - break; - case ERROR_READ: - printf("Can not read %s\n", name); - break; - case ERROR_MEM: - printf("Not enough memory\n"); - break; - } - - free(a); - return 3; - } while (0); - - print_array(a, n, m); - t = clock(); - res = t2_solve(a, n, s); - t = (clock() - t); - printf("New array:\n"); - print_array(a, res, m); - printf("%s : Task = %d Result = %d Elapsed = %.2f\n", - argv[0], task, res, t); - free_array(a, res); - free(a); - a = 0; - return 0; -} diff --git a/2025.02.21/a03.c b/2025.02.21/a03.c deleted file mode 100644 index 072006f..0000000 --- a/2025.02.21/a03.c +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include - -#include "io_status.h" -#include "array.h" -#include "solve.h" - -int main(int argc, char * argv[]) { - int task = 3; - int n = 0, m = 0; - char * name = 0; - char * s = 0; - char ** a = 0; - io_status res; - double t; - - if (!(argc == 5 && sscanf(argv[1], "%d", &n) == 1 && sscanf(argv[2], "%d", &m) == 1)) - { - printf("Usage: %s n m file string\n", argv[0]); - return 1; - } - name = argv[3]; - s = argv[4]; - a = (char **)malloc(n * sizeof(char **)); - if (!a) - { - printf("Can not allocate array len %d\n", n); - return ERROR_MEM; - } - res = read_array(a, n, name); - do { - switch (res) { - case SUCCESS: - continue; - case ERROR_OPEN: - printf("Can not open %s\n", name); - break; - case ERROR_READ: - printf("Can not read %s\n", name); - break; - case ERROR_MEM: - printf("Not enough memory\n"); - break; - } - - free(a); - return 3; - } while (0); - - print_array(a, n, m); - t = clock(); - res = t3_solve(a, n, s); - t = (clock() - t); - printf("New array:\n"); - print_array(a, res, m); - printf("%s : Task = %d Result = %d Elapsed = %.2f\n", - argv[0], task, res, t); - free_array(a, res); - free(a); - a = 0; - return 0; -} diff --git a/2025.02.21/a04.c b/2025.02.21/a04.c deleted file mode 100644 index 9bcfd2b..0000000 --- a/2025.02.21/a04.c +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include - -#include "io_status.h" -#include "array.h" -#include "solve.h" - -int main(int argc, char * argv[]) { - int task = 4; - int n = 0, m = 0; - char * name = 0; - char * s = 0; - char ** a = 0; - io_status res; - double t; - - if (!(argc == 5 && sscanf(argv[1], "%d", &n) == 1 && sscanf(argv[2], "%d", &m) == 1)) - { - printf("Usage: %s n m file string\n", argv[0]); - return 1; - } - name = argv[3]; - s = argv[4]; - a = (char **)malloc(n * sizeof(char **)); - if (!a) - { - printf("Can not allocate array len %d\n", n); - return ERROR_MEM; - } - res = read_array(a, n, name); - do { - switch (res) { - case SUCCESS: - continue; - case ERROR_OPEN: - printf("Can not open %s\n", name); - break; - case ERROR_READ: - printf("Can not read %s\n", name); - break; - case ERROR_MEM: - printf("Not enough memory\n"); - break; - } - - free(a); - return 3; - } while (0); - - print_array(a, n, m); - t = clock(); - res = t4_solve(a, n, s); - t = (clock() - t); - printf("New array:\n"); - print_array(a, res, m); - printf("%s : Task = %d Result = %d Elapsed = %.2f\n", - argv[0], task, res, t); - free_array(a, res); - free(a); - a = 0; - return 0; -} diff --git a/2025.02.21/a05.c b/2025.02.21/a05.c deleted file mode 100644 index ca878c7..0000000 --- a/2025.02.21/a05.c +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include - -#include "io_status.h" -#include "array.h" -#include "solve.h" - -int main(int argc, char * argv[]) { - int task = 5; - int n = 0, m = 0; - char * name = 0; - char * s = 0; - char ** a = 0; - io_status res; - double t; - - if (!(argc == 5 && sscanf(argv[1], "%d", &n) == 1 && sscanf(argv[2], "%d", &m) == 1)) - { - printf("Usage: %s n m file string\n", argv[0]); - return 1; - } - name = argv[3]; - s = argv[4]; - a = (char **)malloc(n * sizeof(char **)); - if (!a) - { - printf("Can not allocate array len %d\n", n); - return ERROR_MEM; - } - res = read_array(a, n, name); - do { - switch (res) { - case SUCCESS: - continue; - case ERROR_OPEN: - printf("Can not open %s\n", name); - break; - case ERROR_READ: - printf("Can not read %s\n", name); - break; - case ERROR_MEM: - printf("Not enough memory\n"); - break; - } - - free(a); - return 3; - } while (0); - - print_array(a, n, m); - t = clock(); - res = t5_solve(a, n, s); - t = (clock() - t); - printf("New array:\n"); - print_array(a, res, m); - printf("%s : Task = %d Result = %d Elapsed = %.2f\n", - argv[0], task, res, t); - free_array(a, res); - free(a); - a = 0; - return 0; -} diff --git a/2025.02.21/a06.c b/2025.02.21/a06.c deleted file mode 100644 index e3decb7..0000000 --- a/2025.02.21/a06.c +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include - -#include "io_status.h" -#include "array.h" -#include "solve.h" - -int main(int argc, char * argv[]) { - int task = 6; - int n = 0, m = 0; - char * name = 0; - char * s = 0; - char ** a = 0; - io_status res; - double t; - - if (!(argc == 5 && sscanf(argv[1], "%d", &n) == 1 && sscanf(argv[2], "%d", &m) == 1)) - { - printf("Usage: %s n m file string\n", argv[0]); - return 1; - } - name = argv[3]; - s = argv[4]; - a = (char **)malloc(n * sizeof(char **)); - if (!a) - { - printf("Can not allocate array len %d\n", n); - return ERROR_MEM; - } - res = read_array(a, n, name); - do { - switch (res) { - case SUCCESS: - continue; - case ERROR_OPEN: - printf("Can not open %s\n", name); - break; - case ERROR_READ: - printf("Can not read %s\n", name); - break; - case ERROR_MEM: - printf("Not enough memory\n"); - break; - } - - free(a); - return 3; - } while (0); - - print_array(a, n, m); - t = clock(); - res = t6_solve(a, n, s); - t = (clock() - t); - printf("New array:\n"); - print_array(a, res, m); - printf("%s : Task = %d Result = %d Elapsed = %.2f\n", - argv[0], task, res, t); - free_array(a, res); - free(a); - a = 0; - return 0; -} diff --git a/2025.02.21/a07.c b/2025.02.21/a07.c deleted file mode 100644 index e3cb05f..0000000 --- a/2025.02.21/a07.c +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include - -#include "io_status.h" -#include "array.h" -#include "solve.h" - -int main(int argc, char * argv[]) { - int task = 7; - int n = 0, m = 0; - char * name = 0; - char * s = 0; - char ** a = 0; - io_status res; - double t; - - if (!(argc == 5 && sscanf(argv[1], "%d", &n) == 1 && sscanf(argv[2], "%d", &m) == 1)) - { - printf("Usage: %s n m file string\n", argv[0]); - return 1; - } - name = argv[3]; - s = argv[4]; - a = (char **)malloc(n * sizeof(char **)); - if (!a) - { - printf("Can not allocate array len %d\n", n); - return ERROR_MEM; - } - res = read_array(a, n, name); - do { - switch (res) { - case SUCCESS: - continue; - case ERROR_OPEN: - printf("Can not open %s\n", name); - break; - case ERROR_READ: - printf("Can not read %s\n", name); - break; - case ERROR_MEM: - printf("Not enough memory\n"); - break; - } - - free(a); - return 3; - } while (0); - - print_array(a, n, m); - t = clock(); - res = t7_solve(a, n, s); - t = (clock() - t); - printf("New array:\n"); - print_array(a, res, m); - printf("%s : Task = %d Result = %d Elapsed = %.2f\n", - argv[0], task, res, t); - free_array(a, res); - free(a); - a = 0; - return 0; -} diff --git a/2025.02.21/a08.c b/2025.02.21/a08.c deleted file mode 100644 index eaae524..0000000 --- a/2025.02.21/a08.c +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include - -#include "io_status.h" -#include "array.h" -#include "solve.h" - -int main(int argc, char * argv[]) { - int task = 8; - int n = 0, m = 0; - char * name = 0; - char * s = 0; - char ** a = 0; - io_status res; - double t; - - if (!(argc == 5 && sscanf(argv[1], "%d", &n) == 1 && sscanf(argv[2], "%d", &m) == 1)) - { - printf("Usage: %s n m file string\n", argv[0]); - return 1; - } - name = argv[3]; - s = argv[4]; - a = (char **)malloc(n * sizeof(char **)); - if (!a) - { - printf("Can not allocate array len %d\n", n); - return ERROR_MEM; - } - res = read_array(a, n, name); - do { - switch (res) { - case SUCCESS: - continue; - case ERROR_OPEN: - printf("Can not open %s\n", name); - break; - case ERROR_READ: - printf("Can not read %s\n", name); - break; - case ERROR_MEM: - printf("Not enough memory\n"); - break; - } - - free(a); - return 3; - } while (0); - - print_array(a, n, m); - t = clock(); - res = t8_solve(a, n, s); - t = (clock() - t); - printf("New array:\n"); - print_array(a, res, m); - printf("%s : Task = %d Result = %d Elapsed = %.2f\n", - argv[0], task, res, t); - free_array(a, res); - free(a); - a = 0; - return 0; -} diff --git a/2025.02.21/array.c b/2025.02.21/array.c deleted file mode 100644 index 7d03417..0000000 --- a/2025.02.21/array.c +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include -#include -#include "io_status.h" -#include "array.h" - - -io_status read_array(char* a[], int n, const char * name) -{ - char buf[LEN] = {0}; - FILE *fp = 0; - int i, j; - - if (!(fp = fopen(name, "r"))) return ERROR_OPEN; - for (i = 0; i < n; i++) { - if (!fgets(buf, sizeof(buf), fp)) - { - fclose(fp); - free_array(a, i); - return ERROR_READ; - } - - for (j = 0; buf[j]; j++) - { - if (buf[j] == '\n') - { - buf[j] = 0; - break; - } - } - - a[i] = (char *)malloc((j+1) * sizeof(char)); - if (!a[i]) - { - fclose(fp); - free_array(a, i); - return ERROR_MEM; - } - - strcpy(a[i], buf); - } - - fclose(fp); - return SUCCESS; -} - - -void free_array(char ** a, int n) -{ - int i; - for(i = 0; i < n; ++i) - { - if (a[i]) - { - free(a[i]); - a[i] = 0; - } - } -} - -void print_array(char ** a, int n, int m) -{ - int l = (n > m ? m : n); - int i; - for (i = 0; i < l; ++i) printf("%s\n", a[i]); -} diff --git a/2025.02.21/array.h b/2025.02.21/array.h deleted file mode 100644 index 4617a02..0000000 --- a/2025.02.21/array.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef ARRAY -#define ARRAY - -#define LEN 1234 - -#include -#include - -#include "io_status.h" - -io_status read_array(char *a[], int n, const char * name); -void free_array(char **a, int n); -void print_array(char **a, int n, int m); - -#endif diff --git a/2025.02.21/io_status.h b/2025.02.21/io_status.h deleted file mode 100644 index 40210e9..0000000 --- a/2025.02.21/io_status.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef IO_STATUS_H -#define IO_STATUS_H - -typedef enum _io_status -{ - SUCCESS, - ERROR_OPEN, - ERROR_READ, - ERROR_MEM -} io_status; - -#endif diff --git a/2025.02.21/solve.c b/2025.02.21/solve.c deleted file mode 100644 index 30145ea..0000000 --- a/2025.02.21/solve.c +++ /dev/null @@ -1,269 +0,0 @@ -#include "solve.h" - -int t1_solve(char ** a, int n, char *s) { - int i, j; - for (i = 0, j = 0; i < n; ++i) { - if (strcmp(a[i], s) >= 0) - { - if (i != j) a[j] = a[i]; - j++; - } else free(a[i]); - } - - for (i = j; i < n; ++i) a[i] = 0; - - return j; -} - -int t2_solve(char ** a, int n, char *s) { - int i, j; - for (i = 0, j = 0; i < n; ++i) { - if (!strstr(s, a[i])) { - if (i != j) - { - a[j] = a[i]; - } - j++; - } else free(a[i]); - } - - for (i = j; i < n; ++i) a[i] = 0; - - return j; -} - -int t3_solve(char ** a, int n, char *s) { - int i, j; - for (i = 0, j = 0; i < n; ++i) { - if (strpbrk(s, a[i])) { - if (i != j) - { - a[j] = a[i]; - } - j++; - } else { - free(a[i]); - } - } - - for (i = j; i < n; ++i) a[i] = 0; - - return j; -} - -int t4_solve(char ** a, int n, char *s) { - size_t len_s = strlen(s); - int i, j, k; - for (i = 0, j = 0, k = 0; i < n; ++i) { - if (len_s <= strlen(a[i])) { - if (i != j) - { - a[j] = a[i]; - } - j++; - k = 0; - } else { - if (k == 0) { - if (i != j) - a[j] = a[i]; - j++; - } else { - free(a[i]); - } - k++; - } - } - - for (i = j; i < n; ++i) a[i] = 0; - - return j; -} - -int t5_solve(char ** a, int n, char *s) { - int i, j, k; - for (i = 0, j = 0, k = 0; i < n; ++i) { - if (!check(a[i], s)) { - if (i != j) - { - a[j] = a[i]; - } - j++; - k = 0; - } else { - if (k == 0) { - if (i != j) - a[j] = a[i]; - j++; - } else { - free(a[i]); - } - k++; - } - } - - for (i = j; i < n; ++i) a[i] = 0; - - return j; -} - - -bool check(char *a, char *s) { - int i; - int len_s = (int)strlen(s); - int len_a = (int)strlen(a); - int diff = len_a - len_s; - - if (diff < 0) return false; - - for (i = (len_a - 1); i > (diff - 1); --i) { - if (a[i] != s[i - diff]) return false; - } - - return true; -} - -int t6_solve(char ** a, int n, char *s) { - int i, j, k; - for (i = 0, j = 0, k = 0; i < n; ++i) { - if (strpbrk(a[i], s)) { - if (k > 1) - { - for (int x = 2; x < k; x++) free(a[i - x]); - a[j++] = a[i - 1]; - } - - if (i != j) - { - a[j] = a[i]; - } - j++; - k = 0; - } else { - if (k == 0) { - if (i != j) - a[j] = a[i]; - j++; - } - k++; - } - } - - if (k > 1) - { - for (int x = 2; x < k; x++) free(a[i - x]); - a[j++] = a[i - 1]; - } - - for (i = j; i < n; ++i) a[i] = 0; - - return j; -} - -int t7_solve(char ** a, int n, char *s) { - bool fl_lst = false, fl_cur = false, fl_nxt = false; - int i, j; - - if (strcmp(a[0], s) < 0) fl_cur = true; - - for (i = 1, j = 0; i < n; ++i) { - if (strcmp(a[i], s) < 0) { - fl_lst = true; - fl_nxt = true; - } - - if (!fl_lst) { - if (j != (i-1)) { - a[j] = a[i-1]; - } - j++; - } else { - free(a[i-1]); - } - - fl_lst = fl_cur; - fl_cur = fl_nxt; - fl_nxt = false; - } - - if (fl_lst) - { - free(a[i-1]); - } else { - a[j++] = a[i-1]; - } - - for (i = j; i < n; ++i) a[i] = 0; - - return j; -} - - -int t8_solve(char ** a, int n, char *s) { - bool fl_lst = false, fl_cur = false, fl_nxt = false; - int i, j; - - fl_cur = is_inside(a[0], s); - - for (i = 1, j = 0; i < n; ++i) { - if (is_inside(a[i], s)) { - fl_lst = true; - fl_nxt = true; - } - - if (!fl_lst) { - if (j != (i-1)) { - a[j] = a[i-1]; - } - j++; - } else { - free(a[i-1]); - } - - fl_lst = fl_cur; - fl_cur = fl_nxt; - fl_nxt = false; - } - - if (fl_lst) - { - free(a[i-1]); - } else { - a[j++] = a[i-1]; - } - - for (i = j; i < n; ++i) a[i] = 0; - - return j; -} - -bool is_inside(char *a, char *s) -{ - int len_s = (int)strlen(s); - int len_a = (int)strlen(a); - int i, j; - - if (len_s < len_a) return false; - - for (i = 0; i < len_s; ++i) { - if (!ccmp(a[0], s[i])) { - if (len_a > (len_s-len_a)) return false; - - for (j = 0; j < len_a; ++j) { - if (ccmp(a[j], s[i + j]) != 0) break; - } - - if (j == len_a) return true; - } - } - - return false; -} - -int ccmp(char a, char b) { - if (LOWER(a)) a -= TO_UPPER; - if (LOWER(b)) b -= TO_UPPER; - - if (a < b) return -1; - if (a > b) return 1; - return 0; -} diff --git a/2025.02.21/solve.h b/2025.02.21/solve.h deleted file mode 100644 index e90508f..0000000 --- a/2025.02.21/solve.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef SOLVE -#define SOLVE - -#include -#include - -#include "array.h" - -#define INF 97 -#define EXTR 122 -#define TO_UPPER 32 - -#define LOWER(a) (INF <= a && a <= EXTR) - -int t1_solve(char **arr, int n, char *s); -int t2_solve(char **arr, int n, char *s); -int t3_solve(char **arr, int n, char *s); -int t4_solve(char **arr, int n, char *s); -int t5_solve(char **arr, int n, char *s); -bool check(char *a, char *s); -int t6_solve(char **arr, int n, char *s); -int t7_solve(char **arr, int n, char *s); -int t8_solve(char **arr, int n, char *s); -bool is_inside(char *a, char *s); -int ccmp(char a, char s); - -#endif diff --git a/2025.05.02/06Ex/comp.h b/2025.05.02/06Ex/comp.h index 6b09d43..0c6fb08 100644 --- a/2025.05.02/06Ex/comp.h +++ b/2025.05.02/06Ex/comp.h @@ -44,7 +44,7 @@ static inline int is_null (const double a) static inline int is_eps (const double a, const double eps) { - return (((a < 0) ? -a : a) - eps) < DBL_EPSILON; + return ((a < 0) ? -a : a) < eps; } #endif diff --git a/2025.05.02/06Ex/solve.c b/2025.05.02/06Ex/solve.c index 167f2c4..6ae1233 100644 --- a/2025.05.02/06Ex/solve.c +++ b/2025.05.02/06Ex/solve.c @@ -11,8 +11,6 @@ int t6_solve ( double a, double b, const double eps, const int M, double *res ) { - double *maximum = d; - const int len = m + 1; double *y_lst = d; @@ -20,8 +18,20 @@ int t6_solve ( double *t_lst = d + (len << 1); int it; + + if (is_eps(y_lst[0], eps)) { + *res = a; + return 1; + } else if (is_eps(y_lst[m], eps)) { + *res = b; + return 1; + } + for (it = 1; it <= M; ++it) { + double maximum = 0; + int max_i = 0; + double x = construct_poly(0, len, y_lst, x_lst); double y = f(x); @@ -42,18 +52,17 @@ int t6_solve ( if (is_equal(y, yi)) return -1; - if ((fabs(yi) - fabs(*maximum)) > DBL_EPSILON) - maximum = y_lst + i; + if ((yi - maximum) > DBL_EPSILON) { + maximum = yi; + max_i = i; + } } - - *maximum = y; - *(maximum + len) = x; - *(maximum + (len << 1)) = x; + + y_lst[max_i] = y; + x_lst[max_i] = x; + t_lst[max_i] = x; } - (void)a; - (void)b; - return -1; } diff --git a/2025.05.02/10Ex/Makefile b/2025.05.02/10Ex/Makefile new file mode 100644 index 0000000..fa7e9c3 --- /dev/null +++ b/2025.05.02/10Ex/Makefile @@ -0,0 +1,42 @@ +WFLAGS = -fstack-protector-all -W -Wall -Wextra -Wunused \ +-Wempty-body -Wlogical-op -Wold-style-declaration -Wmissing-parameter-type \ +-Wignored-qualifiers -Winit-self -Wshadow -Wtype-limits \ +-Wpointer-arith -Wformat-security -Wmissing-format-attribute -Wformat=1 \ +-Wdeclaration-after-statement -Wbad-function-cast -Wnested-externs \ +-Wmissing-prototypes -Wmissing-declarations -Wold-style-definition \ +-Wcast-align -Werror -pedantic -pedantic-errors -Wfloat-equal \ +-Wwrite-strings -Wno-long-long -std=gnu99 -Wstrict-prototypes \ +-Wmissing-field-initializers -Wpointer-sign + +LDFLAGS = -std=gnu99 -mfpmath=sse -O3 +LDLIBS = -lm + +ifeq ($(OS),Windows_NT) + EXE = exe + CLEAN = del + LDLIBS += -lssp +else + EXE = out + CLEAN = rm -f +endif + +TARGET = a10.$(EXE) +OBJ = main.o solve.o init_f.o + +%.o: %.c + gcc $(WFLAGS) $(LDFLAGS) -c $< -o $@ + +$(TARGET): $(OBJ) + gcc $^ -o $@ $(LDLIBS) + +# Отладочная сборка (gdb) +gdb: LDFLAGS = -std=gnu99 -mfpmath=sse -g -O0 +gdb: clean $(TARGET) + +# Профилировочная сборка (gprof) +prof: LDFLAGS += -pg +prof: LDLIBS += -pg +prof: clean $(TARGET) + +clean: + $(CLEAN) *.o *$(EXE) diff --git a/2025.05.02/10Ex/init_f.c b/2025.05.02/10Ex/init_f.c new file mode 100644 index 0000000..22eb5ea --- /dev/null +++ b/2025.05.02/10Ex/init_f.c @@ -0,0 +1,61 @@ +#include "init_f.h" + +#include + + +static int cl = 0; + +int get_call_count (void) +{ + return cl; +} + +double f0 (double x) +{ + cl++; + (void)x; + + return 1; +} + +double f1 (double x) +{ + cl++; + return (x * 1e-100) - 1.0; +} + +double f2 (double x) +{ + cl++; + return 4 - x * x; +} + +double f3 (double x) +{ + double x_2 = x * x; + cl++; + + return x * x_2 + 3 * x_2 + 16; +} + +double f4 (double x) +{ + double x_2 = x * x; + cl++; + + return 3 - 2 * x_2 - x_2 * x_2; +} + +double f5 (double x) +{ + cl++; + return sqrt(fabs(x) + 1) - 2; +} + +double f6 (double x) +{ + cl++; + return sqrt(sqrt(fabs(x) + 1) + 1) - 2; +} + + diff --git a/2025.05.02/10Ex/init_f.h b/2025.05.02/10Ex/init_f.h new file mode 100644 index 0000000..ee5e8e8 --- /dev/null +++ b/2025.05.02/10Ex/init_f.h @@ -0,0 +1,13 @@ +#ifndef INIT_F_H +#define INIT_F_H + +int get_call_count (void); +double f0 (double x); +double f1 (double x); +double f2 (double x); +double f3 (double x); +double f4 (double x); +double f5 (double x); +double f6 (double x); + +#endif diff --git a/2025.05.02/10Ex/main.c b/2025.05.02/10Ex/main.c new file mode 100644 index 0000000..9676378 --- /dev/null +++ b/2025.05.02/10Ex/main.c @@ -0,0 +1,49 @@ +#include +#include +#include + +#include "init_f.h" +#include "solve.h" + +/* ./a.out a b eps M k */ +int main(int argc, char *argv[]) +{ + double t, a, b, eps, x = 0; + int m, k, cl, it, task = 10; + + double (*f) (double); + double (*f_lst[]) (double) = {f0, f1, f2, f3, f4, f5, f6}; + int len_f = sizeof(f_lst) / sizeof(f_lst[0]); + + if ( + !((argc == 6) && + sscanf(argv[1], "%lf", &a) == 1 && + sscanf(argv[2], "%lf", &b) == 1 && + (a <= b) && + (sscanf(argv[3], "%lf", &eps) == 1 && (eps >= 0)) && + ((sscanf(argv[4], "%d", &m) == 1) && m > 0) && + ((sscanf(argv[5], "%d", &k) == 1) && ((0 <= k) && (k <= len_f)))) + ) { + fprintf(stderr, "Usage: %s a b eps M k\n", argv[0]); + return -1; + } + + f = f_lst[k]; + + t = clock(); + it = t10_solve(f, a, b, eps, m, &x); + t = (clock() - t) / CLOCKS_PER_SEC; + + cl = get_call_count(); + + if (it < 0) + { + fprintf(stdout, "%s : Task = %d NOT FOUND Count = %d T = %.2f\n", argv[0], task, cl, t); + return -2; + } else + { + printf("%s : Task = %d X = %e Res = %e Its = %d Count = %d T = %.2f\n", argv[0], task, x, f(x), it, cl, t); + return 0; + } +} + diff --git a/2025.05.02/10Ex/solve.c b/2025.05.02/10Ex/solve.c new file mode 100644 index 0000000..958f299 --- /dev/null +++ b/2025.05.02/10Ex/solve.c @@ -0,0 +1,74 @@ +#include "solve.h" + +#include +#include +#include +#include +#include + +int t5_solve ( + double (*f) (double), + double a, double b, + double eps, int m, double *x +) { + int it; + double c = (a + b) * 0.5; + + double y_a = f(a); + double y_c = f(c); + double y_b = f(b); + + if (is_null(y_a)) { + *x = a; + return 1; + } else if (is_null(y_b)) { + *x = b; + return 1; + } else if (is_null(y_c)) { + *x = c; + return 1; + } + + if (is_equal(a, b)) + return -1; + else if (is_equal(a, c)) + return -1; + else if (is_equal(b, c)) + return -1; + + for (it = 1; it <= m; ++it) + { + double *temp_pnt = 0, *inner_max_pnt; + const double x_new = a - + angle * y_a + + ((((b - c) / (y_b - y_c)) - angle) / (y_b - y_a)) * y_a * y_c; + const double y_new = f(x_new); + + if (is_eps(y_new, eps)) + { + *x = x_new; + return it; + } + + if ( + is_equal(x_new, a) || + is_equal(x_new, c) || + is_equal(x_new, b) + ) + return -1; + + inner_max_pnt = fp_abs_max(&c, &b, &y_c, &y_b, &temp_pnt); + *fp_abs_max(&a, inner_max_pnt, &y_a, temp_pnt, &temp_pnt) = x_new; + *temp_pnt = y_new; + } + + if (it > m) + return -2; + else + { + double temp = 0, *temp_x_pnt = fpmax(&c, &b, -y_c, -y_b, &temp); + *x = *fpmax(&a, temp_x_pnt, -y_a, temp, &temp); + return it; + } +} + diff --git a/2025.05.02/10Ex/solve.h b/2025.05.02/10Ex/solve.h new file mode 100644 index 0000000..1ff07f7 --- /dev/null +++ b/2025.05.02/10Ex/solve.h @@ -0,0 +1,56 @@ +#ifndef SOLVE_H +#define SOLVE_H + +#include +#include + +static inline double * fpmax (double *pa, double *pb, double fa, double fb, double *max_f_p) +{ + if ((fa - fb) > DBL_EPSILON) + { + *max_f_p = fa; + return pa; + } else + { + *max_f_p = fb; + return pb; + } +} + +static inline double * fp_abs_max (double *pa, double *pb, double *fa, double *fb, double **max_f_p) +{ + if ((fabs(*fa) - fabs(*fb)) > DBL_EPSILON) + { + *max_f_p = fa; + return pa; + } else + { + *max_f_p = fb; + return pb; + } +} + +static inline int is_equal (const double a, const double b) +{ + double diff = a - b; + double max_val = (a > b) ? a : b; + return ((diff < 0) ? -diff : diff) < (DBL_EPSILON * max_val); +} + +static inline int is_null (const double a) +{ + return ((a < 0) ? -a : a) < DBL_EPSILON; +} + +static inline int is_eps (const double a, const double eps) +{ + return (((a < 0) ? -a : a) - eps) < DBL_EPSILON; +} + +int t5_solve ( + double (*f) (double), + double a, double b, + double eps, int m, double *x + ); + +#endif diff --git a/2025.05.02/dist/Krivoruchenko_SK/a05.c b/2025.05.02/dist/Krivoruchenko_SK/a05.c new file mode 100644 index 0000000..befd203 --- /dev/null +++ b/2025.05.02/dist/Krivoruchenko_SK/a05.c @@ -0,0 +1,49 @@ +#include +#include +#include + +#include "init_f.h" +#include "solve.h" + +/* ./a.out a b eps M k */ +int main(int argc, char *argv[]) +{ + double t, a, b, eps, x = 0; + int m, k, cl, it, task = 5; + + double (*f) (double); + double (*f_lst[]) (double) = {f0, f1, f2, f3, f4, f5, f6}; //TODO: Rem f7 + int len_f = sizeof(f_lst) / sizeof(f_lst[0]); + + if ( + !((argc == 6) && + sscanf(argv[1], "%lf", &a) == 1 && + sscanf(argv[2], "%lf", &b) == 1 && + (a <= b) && + (sscanf(argv[3], "%lf", &eps) == 1 && (eps >= 0)) && + ((sscanf(argv[4], "%d", &m) == 1) && m > 0) && + ((sscanf(argv[5], "%d", &k) == 1) && ((0 <= k) && (k <= len_f)))) + ) { + fprintf(stderr, "Usage: %s a b eps M k\n", argv[0]); + return -1; + } + + f = f_lst[k]; + + t = clock(); + it = t5_solve(f, a, b, eps, m, &x); + t = (clock() - t) / CLOCKS_PER_SEC; + + cl = get_call_count(); + + if (it < 0) + { + fprintf(stdout, "%s : Task = %d NOT FOUND Count = %d T = %.2f\n", argv[0], task, cl, t); + return -2; + } else + { + printf("%s : Task = %d X = %e Res = %e Its = %d Count = %d T = %.2f\n", argv[0], task, x, f(x), it, cl, t); + return 0; + } +} + diff --git a/2025.05.02/dist/Krivoruchenko_SK/a06.c b/2025.05.02/dist/Krivoruchenko_SK/a06.c new file mode 100644 index 0000000..11c7d05 --- /dev/null +++ b/2025.05.02/dist/Krivoruchenko_SK/a06.c @@ -0,0 +1,66 @@ +#include +#include +#include +#include + +#include "init_f.h" +#include "array_io.h" +#include "solve.h" + +/* ./a.out m a b eps M k */ +int main(int argc, char *argv[]) +{ + double t = 0, *d, a, b, eps, x = 0; + int deg_poly, num_iter, k, cl, it, task = 6; + + double (*f) (double); + double (*f_lst[]) (double) = {f0, f1, f2, f3, f4, f5, f6}; + int len_f = sizeof(f_lst) / sizeof(f_lst[0]); + + if ( + !((argc == 7) && + sscanf(argv[1], "%d", °_poly) == 1 && + sscanf(argv[2], "%lf", &a) == 1 && + sscanf(argv[3], "%lf", &b) == 1 && + (a <= b) && + (sscanf(argv[4], "%lf", &eps) == 1 && (eps >= 0)) && + ((sscanf(argv[5], "%d", &num_iter) == 1) && num_iter > 0) && + ((sscanf(argv[6], "%d", &k) == 1) && ((0 <= k) && (k <= len_f)))) + ) { + fprintf(stderr, "Usage: %s m a b eps M k\n", argv[0]); + return -1; + } + + d = (double *)malloc(3 * (deg_poly + 1) * sizeof(double)); + if (!d) + { + fprintf(stderr, "Error: Not enough memory!\n"); + return -2; + } + + f = f_lst[k]; + + it = init_array(f, d, deg_poly, a, b, eps, &x); + + if (!it) + { + t = clock(); + it = t6_solve(f, deg_poly, d, a, b, eps, num_iter, &x); + t = (clock() - t) / CLOCKS_PER_SEC; + } + + cl = get_call_count(); + + free(d); + + if (it < 0) + { + fprintf(stdout, "%s : Task = %d NOT FOUND Count = %d T = %.2f\n", argv[0], task, cl, t); + return -2; + } else + { + fprintf(stdout, "%s : Task = %d X = %e Res = %e Its = %d Count = %d T = %.2f\n", argv[0], task, x, f(x), it, cl, t); + return 0; + } +} + diff --git a/2025.05.02/dist/Krivoruchenko_SK/array_io.c b/2025.05.02/dist/Krivoruchenko_SK/array_io.c new file mode 100644 index 0000000..7b47192 --- /dev/null +++ b/2025.05.02/dist/Krivoruchenko_SK/array_io.c @@ -0,0 +1,41 @@ +#include "array_io.h" +#include "comp.h" + +int init_array ( + double (*f) (double), + double *d, int m, + double a, double b, + double eps, double *ret +) { + const double h = (b - a) / m; + const int len = m+1; + + double *y_lst = d; + double *x_lst = d + len; + double *t_lst = d + (len << 1); + + double x = a; + + for (int i = 0; i < len; ++i) + { + double y = f(x); + + if (is_eps(y, eps)) + { + *ret = x; + return 1; + } + + for (int j = 0; j < i; ++j) + if (is_equal(y, y_lst[j])) + return -1; + + y_lst[i] = y; + x_lst[i] = x; + t_lst[i] = x; + + x += h; + } + + return 0; +} diff --git a/2025.05.02/dist/Krivoruchenko_SK/array_io.h b/2025.05.02/dist/Krivoruchenko_SK/array_io.h new file mode 100644 index 0000000..15cebe3 --- /dev/null +++ b/2025.05.02/dist/Krivoruchenko_SK/array_io.h @@ -0,0 +1,11 @@ +#ifndef ARRAY_IO_H +#define ARRAY_IO_H + +int init_array ( + double (*f) (double), + double *d, int m, + double a, double b, + double eps, double *ret +); + +#endif diff --git a/2025.05.02/dist/Krivoruchenko_SK/comp.h b/2025.05.02/dist/Krivoruchenko_SK/comp.h new file mode 100644 index 0000000..6b09d43 --- /dev/null +++ b/2025.05.02/dist/Krivoruchenko_SK/comp.h @@ -0,0 +1,50 @@ +#ifndef COMP_H +#define COMP_H + +#include +#include + +static inline double * fpmax (double *pa, double *pb, double fa, double fb, double *max_f_p) +{ + if ((fa - fb) > DBL_EPSILON) + { + *max_f_p = fa; + return pa; + } else + { + *max_f_p = fb; + return pb; + } +} + +static inline double * fp_abs_max (double *pa, double *pb, double *fa, double *fb, double **max_f_p) +{ + if ((fabs(*fa) - fabs(*fb)) > DBL_EPSILON) + { + *max_f_p = fa; + return pa; + } else + { + *max_f_p = fb; + return pb; + } +} + +static inline int is_equal (const double a, const double b) +{ + double diff = a - b; + double max_val = (a > b) ? a : b; + return ((diff < 0) ? -diff : diff) < (DBL_EPSILON * max_val); +} + +static inline int is_null (const double a) +{ + return ((a < 0) ? -a : a) < DBL_EPSILON; +} + +static inline int is_eps (const double a, const double eps) +{ + return (((a < 0) ? -a : a) - eps) < DBL_EPSILON; +} + +#endif diff --git a/2025.05.02/dist/Krivoruchenko_SK/init_f.c b/2025.05.02/dist/Krivoruchenko_SK/init_f.c index b14a5a9..7314dd0 100644 --- a/2025.05.02/dist/Krivoruchenko_SK/init_f.c +++ b/2025.05.02/dist/Krivoruchenko_SK/init_f.c @@ -1,128 +1,66 @@ #include "init_f.h" #include -#include -static int cl_f = 0; -static int cl_d = 0; +static int cl = 0; int get_call_count (void) { - return cl_f; -} - -int get_call_function_count (void) -{ - return cl_f; -} - -int get_call_derivative_count (void) -{ - return cl_d; + return cl; } double f0 (double x) { - cl_f++; + cl++; (void)x; return 1; } -double d0 (double x) -{ - cl_d++; - (void)x; - - return 0; -} - double f1 (double x) { - cl_f++; - return ((x * 1e-100) - 1.0) * 1e100; -} - -double d1 (double x) -{ - (void)x; - cl_d++; - return 1; + cl++; + return (x * 1e-100) - 1.0; } double f2 (double x) { - cl_f++; - return 4 - x * x; -} - -double d2 (double x) -{ - cl_d++; - return -2 * x; + double x_2 = x * x; + cl++; + return 4 - x_2; } double f3 (double x) { double x_2 = x * x; - cl_f++; + double x_3 = x * x_2; + cl++; - return x * x_2 + 3 * x_2 + 16; -} - -double d3 (double x) -{ - cl_d++; - - return 3 * x * x + 6 * x; + return x_3 + 3 * x_2 + 16; } double f4 (double x) { double x_2 = x * x; - cl_f++; + double x_4 = x_2 * x_2; + cl++; - return 3 - 2 * x_2 - x_2 * x_2; -} - -double d4 (double x) -{ - cl_d++; - - return -4 * x - 4 * ((x * x) * x); + return 3 - 2 * x_2 - x_4; } double f5 (double x) { - cl_f++; - return sqrt(fabs(x) + 1) - 2; -} - -double d5 (double x) -{ - cl_d++; - if (x < -DBL_EPSILON) - return (-1.0 / (sqrt(fabs(x) + 1))) * 0.5; - else if (x > DBL_EPSILON) - return (1.0 / (sqrt(fabs(x) + 1))) * 0.5; - return 0; + double sq_x = sqrt(fabs(x) + 1); + cl++; + return sq_x - 2; } double f6 (double x) { - cl_f++; - return sqrt(sqrt(fabs(x) + 1) + 1) - 2; + double sq_x = sqrt(fabs(x) + 1); + double sq = sqrt(sq_x + 1); + cl++; + return sq - 2; } -double d6 (double x) -{ - double sqrt_x = sqrt(fabs(x) + 1); - cl_d++; - - if (x < -DBL_EPSILON) - return (-1.0 / (sqrt(sqrt_x + 1) * sqrt_x)) * 0.25; - else if (x > DBL_EPSILON) - return (1.0 / (sqrt(sqrt_x + 1) * sqrt_x)) * 0.25; - return 0; -} diff --git a/2025.05.02/dist/Krivoruchenko_SK/polynom.c b/2025.05.02/dist/Krivoruchenko_SK/polynom.c new file mode 100644 index 0000000..3a68254 --- /dev/null +++ b/2025.05.02/dist/Krivoruchenko_SK/polynom.c @@ -0,0 +1,43 @@ +#include "polynom.h" + +#include +#include +#include + +// the Newton interpolation polynomial +double construct_poly (const double x_0, const int n, const double * restrict X, double * restrict Y) +{ + double value, start_value; + + for (int k = 0; k < n-1; ++k) + { + double last_x; + double last_y = Y[n-1]; + + for (int i = n-2; i >= k; --i) + { + const double x_i = X[i-k]; + const double y_i = Y[i]; + last_x = X[i+1]; + + if (fabs(last_x - x_i) < DBL_EPSILON) + return DBL_MAX; + + Y[i+1] = (last_y - y_i) / (last_x - x_i); + + last_y = y_i; + } + } + + start_value = 1; + value = 0; + + for (int i = 0; i < n; ++i) + { + value += Y[i] * start_value; + start_value *= (x_0 - X[i]); + } + + return value; +} + diff --git a/2025.05.02/dist/Krivoruchenko_SK/polynom.h b/2025.05.02/dist/Krivoruchenko_SK/polynom.h new file mode 100644 index 0000000..65611c0 --- /dev/null +++ b/2025.05.02/dist/Krivoruchenko_SK/polynom.h @@ -0,0 +1,6 @@ +#ifndef POLYNOM_H +#define POLYNOM_H + +double construct_poly (const double x_0, const int n, const double * restrict X, double * restrict Y); + +#endif diff --git a/2025.05.02/tests/6th_test.sh b/2025.05.02/tests/6th_test.sh index d25d3d5..9281b12 100755 --- a/2025.05.02/tests/6th_test.sh +++ b/2025.05.02/tests/6th_test.sh @@ -1,7 +1,9 @@ script_name="$(basename "$0")" +prog="6" + iter="1000" poly_deg="10" -prog="6" +eps="1e-14" mkdir -p tests @@ -17,25 +19,35 @@ if [ ! -f a0$prog.out ]; then exit 1 fi +outlog="$(pwd)/tests/out_a0${prog}_$script_name.log" +errlog="$(pwd)/tests/err_a0${prog}_$script_name.log" + +rm -f $outlog $errlog + echo "Тест запущен..." for (( k = 3 ; k < 7; k++ )); do - echo "------- K = $k -------" for (( a = -100 ; a < -40 ; a++ )); do for (( b = -9 ; b < 10 ; b++ )); do - echo "./a0$prog.out $poly_deg "$(echo "$a / 10" | bc -l)" "$(echo "$b / 10" | bc -l)" 1e-16 $iter $k" - ./a0$prog.out $poly_deg "$(echo "$a / 10" | bc -l)" "$(echo "$b / 10" | bc -l)" 1e-16 $iter $k + x="$(echo "$a / 10" | bc -l)" + y="$(echo "$b / 10" | bc -l)" + cmd="./a0$prog.out $poly_deg $x $y $eps $iter $k" + echo "$cmd" + $cmd done done for (( a = -9 ; a < 10 ; a++ )); do for (( b = 11 ; b < 100 ; b++ )); do - echo "./a0$prog.out $poly_deg "$(echo "$a / 10" | bc -l)" "$(echo "$b / 10" | bc -l)" 1e-16 $iter $k" - ./a0$prog.out $poly_deg "$(echo "$a / 10" | bc -l)" "$(echo "$b / 10" | bc -l)" 1e-16 $iter $k + x="$(echo "$a / 10" | bc -l)" + y="$(echo "$b / 10" | bc -l)" + cmd="./a0$prog.out $poly_deg $x $y $eps $iter $k" + echo "$cmd" + $cmd done done -done >$(pwd)/tests/out_$script_name.log 2>$(pwd)/tests/err_$script_name.log +done >$outlog 2>$errlog -echo "Тест записан в ./tests/out_$script_name.log" -echo "Ошибки записаны в ./tests/err_$script_name.log" +echo "Тест записан в $outlog" +echo "Ошибки записаны в $errlog" echo "Тест завершен" diff --git a/2025.05.02/tests/main_test.sh b/2025.05.02/tests/main_test.sh index 80e58e7..aac6f9a 100755 --- a/2025.05.02/tests/main_test.sh +++ b/2025.05.02/tests/main_test.sh @@ -8,7 +8,7 @@ if [ "$#" -ne 1 ]; then exit 1 fi -prog=$1 +prog=$(printf "%02d" "$1") mkdir -p tests @@ -24,10 +24,10 @@ if [ ! -f a0$prog.out ]; then exit 2 fi -outlog="$(pwd)/tests/out_a0${prog}_$script_name.log" -errlog="$(pwd)/tests/err_a0${prog}_$script_name.log" +outlog="$(pwd)/tests/out_a${prog}_$script_name.log" +errlog="$(pwd)/tests/err_a${prog}_$script_name.log" -rm -f $outlog $errlog +rm -f "$outlog" "$errlog" echo "Тест запущен..." @@ -37,14 +37,14 @@ for (( k = 3 ; k < 7; k++ )); do for (( a = -100 ; a < -40 ; a++ )); do for (( b = -9 ; b < 10 ; b++ )); do echo "./a0$prog.out "$(echo "$a / 10" | bc -l)" "$(echo "$b / 10" | bc -l)" $eps $iter $k" - echo "$i $(./a0$prog.out "$(echo "$a / 10" | bc -l)" "$(echo "$b / 10" | bc -l)" $eps $iter $k)" + echo "$i $(./a$prog.out "$(echo "$a / 10" | bc -l)" "$(echo "$b / 10" | bc -l)" $eps $iter $k)" ((i+=2)) done done for (( a = -9 ; a < 10 ; a++ )); do for (( b = 11 ; b < 100 ; b++ )); do echo "$i ./a0$prog.out "$(echo "$a / 10" | bc -l)" "$(echo "$b / 10" | bc -l)" $eps $iter $k" - echo "$i $(./a0$prog.out "$(echo "$a / 10" | bc -l)" "$(echo "$b / 10" | bc -l)" $eps $iter $k)" + echo "$i $(./a$prog.out "$(echo "$a / 10" | bc -l)" "$(echo "$b / 10" | bc -l)" $eps $iter $k)" ((i+=2)) done done