diff --git a/2025.05.23/09Ex/solve.c b/2025.05.23/09Ex/solve.c index eae4baa..3f63269 100644 --- a/2025.05.23/09Ex/solve.c +++ b/2025.05.23/09Ex/solve.c @@ -7,72 +7,67 @@ node * t9_solve (node *head) { - node *last, *curr = head, *next, - *deleted = NULL, *last_cmp; - int cmp; + int cmp_last, cmp_next; + node *last, *curr, *next, + *deleted; + last=next=deleted=NULL; + cmp_last=cmp_next=0; + curr = head; + if (!curr) + return NULL; - next = head->next; - if (!next) - return head; - - cmp = strcmp(curr->string, next->string); - if (cmp >= 0) { - deleted = curr; - - head = next; - curr = next; - next = next->next; - - if (!next) { - delete_node(deleted); - if (cmp == 0) - delete_node(curr); - return NULL; - } - } - - for (next = curr->next; next->next;) + for (next = curr->next; next; next = curr->next) { - last_cmp = curr; - - last = curr; - curr = next; - next = curr->next; - if (deleted) - last_cmp = deleted; + cmp_last = strcmp(curr->string, deleted->string); + else if (!last) + cmp_last = 1; + else + cmp_last = strcmp(curr->string, last->string); + cmp_next = strcmp(curr->string, next->string); // Как происходит обращение в память для структур? - if ( - (strcmp(curr->string, next->string) >= 0) && - (strcmp(curr->string, last_cmp->string) >= 0) - ) { + if ((cmp_last >= 0) && (cmp_next >= 0)) + { if (deleted) delete_node(deleted); deleted = curr; - - last->next = next; - curr = last; - } else { + if (last) { + last->next = next; + curr = last; + } else { + head = next; + curr = NULL; + } + } else + { if (deleted) delete_node(deleted); deleted = NULL; } + last = curr; + curr = next; } if (deleted) - last_cmp = deleted; + cmp_last = strcmp(curr->string, deleted->string); + else if (!last) + cmp_last = 1; else - last_cmp = curr; + cmp_last = strcmp(curr->string, last->string); - if (strcmp(next->string, last_cmp->string) >= 0) { - curr->next = NULL; - - delete_node(next); + if (cmp_last >= 0) + { + delete_node(curr); + if (last) + last->next = NULL; + else + head = NULL; + curr = NULL; } if (deleted) delete_node(deleted); - return head; + return head; } diff --git a/2025.05.23/Krivoruchenko_SK.zip b/2025.05.23/Krivoruchenko_SK.zip new file mode 100644 index 0000000..b86b3e6 Binary files /dev/null and b/2025.05.23/Krivoruchenko_SK.zip differ diff --git a/2025.05.23/dist/Krivoruchenko_SK/Makefile b/2025.05.23/dist/Krivoruchenko_SK/Makefile index da157db..ac6435e 100644 --- a/2025.05.23/dist/Krivoruchenko_SK/Makefile +++ b/2025.05.23/dist/Krivoruchenko_SK/Makefile @@ -2,17 +2,17 @@ FLAGS = -fstack-protector-all -W -Wall -Wextra -Wunused -Wcast-align -Werror -pe OBJ_COMMON = io_node.o -NUMS = 1 2 3 4 5 6 7 8 9 10 11 12 +NUMS = 1 2 3 4 5 6 7 8 9 10 OUTS = $(foreach n,$(NUMS),$(shell printf "a%02d.out\n" "$(n)")) all: $(OUTS) %.o: %.c - gcc -c $(FLAGS) $< + -gcc -c $(FLAGS) $< a%.out: main_%.o solve_%.o $(OBJ_COMMON) - gcc $(FLAGS) $^ -o $@ -lm + -gcc $(FLAGS) $^ -o $@ -lm clean: rm -f *.o *.out diff --git a/2025.05.23/dist/Krivoruchenko_SK/io_node.c b/2025.05.23/dist/Krivoruchenko_SK/io_node.c index 2a8e254..23652e5 100644 --- a/2025.05.23/dist/Krivoruchenko_SK/io_node.c +++ b/2025.05.23/dist/Krivoruchenko_SK/io_node.c @@ -17,6 +17,17 @@ int get_length (node * head) return i; } +void delete_nodes (node *head, const int count) +{ + for (int i = 0; i < count; ++i) + { + node *temp = head; + head = head->next; + + delete_node(temp); + } +} + void delete_list (node * head) { node *curr, *next; diff --git a/2025.05.23/dist/Krivoruchenko_SK/io_node.h b/2025.05.23/dist/Krivoruchenko_SK/io_node.h index e4b5399..db51796 100644 --- a/2025.05.23/dist/Krivoruchenko_SK/io_node.h +++ b/2025.05.23/dist/Krivoruchenko_SK/io_node.h @@ -13,6 +13,7 @@ static inline void delete_node (node *head) } int get_length (node *head); +void delete_nodes (node *head, const int count); void delete_list (node *head); io_status read_list (node **list, const char *filename); void print_list (node *head, const int p); diff --git a/2025.05.23/dist/Krivoruchenko_SK/main_09.c b/2025.05.23/dist/Krivoruchenko_SK/main_09.c new file mode 100644 index 0000000..d93e44e --- /dev/null +++ b/2025.05.23/dist/Krivoruchenko_SK/main_09.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include + +#include "solve_09.h" +#include "node.h" +#include "io_node.h" +#include "status.h" + +/* ./a09.out p filename */ +int main (int argc, char *argv[]) +{ + node *head; + char *name; + double t; + int p, len, task = 9; + io_status ret; + + if ( + !((argc == 3) && + sscanf(argv[1], "%d", &p) == 1 && + argv[2]) + ) { + fprintf(stderr, "Usage: %s p filename\n", argv[0]); + return -1; + } + + name = argv[2]; + + ret = read_list(&head, name); + do { + switch (ret) { + case SUCCESS: + continue; + case ERR_OPEN: + fprintf (stderr, "%s '%s'!\n", ERR_MSG_OPEN, name); + break; + case ERR_READ: + fprintf (stderr, "%s '%s'!\n", ERR_MSG_READ, name); + break; + case ERR_MEM: + fprintf (stderr, "%s!\n", ERR_MSG_MEM); + break; + } + + delete_list(head); + return -2; + } while (0); + + fprintf (stdout, "Source list:\n"); + print_list(head, p); + + t = clock(); + head = t9_solve(head); + t = (clock() - t) / CLOCKS_PER_SEC; + + fprintf (stdout, "\nFinal list:\n"); + print_list(head, p); + len = get_length(head); + + delete_list(head); + + fprintf (stdout, "%s : Task = %d Length = %d Elapsed = %.2f\n", argv[0], task, len, t); + return 0; +} + diff --git a/2025.05.23/dist/Krivoruchenko_SK/main_10.c b/2025.05.23/dist/Krivoruchenko_SK/main_10.c new file mode 100644 index 0000000..11646f0 --- /dev/null +++ b/2025.05.23/dist/Krivoruchenko_SK/main_10.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include + +#include "solve_10.h" +#include "node.h" +#include "io_node.h" +#include "status.h" + +/* ./a10.out p filename */ +int main (int argc, char *argv[]) +{ + node *head; + char *name; + double t; + int p, len, task = 10; + io_status ret; + + if ( + !((argc == 3) && + sscanf(argv[1], "%d", &p) == 1 && + argv[2]) + ) { + fprintf(stderr, "Usage: %s p filename\n", argv[0]); + return -1; + } + + name = argv[2]; + + ret = read_list(&head, name); + do { + switch (ret) { + case SUCCESS: + continue; + case ERR_OPEN: + fprintf (stderr, "%s '%s'!\n", ERR_MSG_OPEN, name); + break; + case ERR_READ: + fprintf (stderr, "%s '%s'!\n", ERR_MSG_READ, name); + break; + case ERR_MEM: + fprintf (stderr, "%s!\n", ERR_MSG_MEM); + break; + } + + delete_list(head); + return -2; + } while (0); + + fprintf (stdout, "Source list:\n"); + print_list(head, p); + + t = clock(); + head = t10_solve(head); + t = (clock() - t) / CLOCKS_PER_SEC; + + fprintf (stdout, "\nFinal list:\n"); + print_list(head, p); + len = get_length(head); + + delete_list(head); + + fprintf (stdout, "%s : Task = %d Length = %d Elapsed = %.2f\n", argv[0], task, len, t); + return 0; +} + diff --git a/2025.05.23/dist/Krivoruchenko_SK/solve_09.c b/2025.05.23/dist/Krivoruchenko_SK/solve_09.c new file mode 100644 index 0000000..ffb3bdc --- /dev/null +++ b/2025.05.23/dist/Krivoruchenko_SK/solve_09.c @@ -0,0 +1,73 @@ +#include "solve_09.h" +#include "node.h" +#include "io_node.h" + +#include +#include + +node * t9_solve (node *head) +{ + int cmp_last, cmp_next; + node *last, *curr, *next, + *deleted; + last=next=deleted=NULL; + cmp_last=cmp_next=0; + curr = head; + if (!curr) + return NULL; + + for (next = curr->next; next; next = curr->next) + { + if (deleted) + cmp_last = strcmp(curr->string, deleted->string); + else if (!last) + cmp_last = 1; + else + cmp_last = strcmp(curr->string, last->string); + cmp_next = strcmp(curr->string, next->string); // Как происходит обращение в память для структур? + + if ((cmp_last >= 0) && (cmp_next >= 0)) + { + if (deleted) + delete_node(deleted); + deleted = curr; + if (last) { + last->next = next; + curr = last; + } else { + head = next; + curr = NULL; + } + } else + { + if (deleted) + delete_node(deleted); + deleted = NULL; + } + last = curr; + curr = next; + } + + if (deleted) + cmp_last = strcmp(curr->string, deleted->string); + else if (!last) + cmp_last = 1; + else + cmp_last = strcmp(curr->string, last->string); + + if (cmp_last >= 0) + { + delete_node(curr); + if (last) + last->next = NULL; + else + head = NULL; + curr = NULL; + } + + if (deleted) + delete_node(deleted); + + return head; +} + diff --git a/2025.05.23/dist/Krivoruchenko_SK/solve_09.h b/2025.05.23/dist/Krivoruchenko_SK/solve_09.h new file mode 100644 index 0000000..30a5df5 --- /dev/null +++ b/2025.05.23/dist/Krivoruchenko_SK/solve_09.h @@ -0,0 +1,8 @@ +#ifndef SOLVE_H +#define SOLVE_H + +#include "node.h" + +node * t9_solve (node *head); + +#endif diff --git a/2025.05.23/dist/Krivoruchenko_SK/solve_10.c b/2025.05.23/dist/Krivoruchenko_SK/solve_10.c new file mode 100644 index 0000000..51f60e7 --- /dev/null +++ b/2025.05.23/dist/Krivoruchenko_SK/solve_10.c @@ -0,0 +1,56 @@ +#include "solve_10.h" +#include "node.h" +#include "io_node.h" + +#include +#include + +node * t10_solve (node *head) +{ + int down = 0; + node *last, *curr, *next, + *start; + last=next=start=NULL; + curr = head; + + for (next=curr->next; next; next=curr->next) + { + if (strcmp(next->string, curr->string) <= 0) { + if (!down) + start = last; + down++; + } else { + if (down) { + if (start) { + delete_nodes(start->next, down+1); + start->next = next; + last = start; + } else { + delete_nodes(head, down+1); + head = next; + last = NULL; + } + curr = NULL; + } + down = 0; + } + + last = curr; + curr = next; + } + + if (down) { + if (start) { + delete_nodes(start->next, down+1); + start->next = NULL; + } else { + delete_nodes(head, down+1); + head = NULL; + } + curr = NULL; + last = NULL; + } + + return head; +} + diff --git a/2025.05.23/dist/Krivoruchenko_SK/solve_10.h b/2025.05.23/dist/Krivoruchenko_SK/solve_10.h new file mode 100644 index 0000000..f080366 --- /dev/null +++ b/2025.05.23/dist/Krivoruchenko_SK/solve_10.h @@ -0,0 +1,8 @@ +#ifndef SOLVE_H +#define SOLVE_H + +#include "node.h" + +node * t10_solve (node *head); + +#endif diff --git a/2025.05.23/tests/file_test.sh b/2025.05.23/tests/file_test.sh index cc0e05c..46415df 100755 --- a/2025.05.23/tests/file_test.sh +++ b/2025.05.23/tests/file_test.sh @@ -19,7 +19,7 @@ rm -f "$outlog" "$errlog" echo "Тест запущен..." -for npr in {1..7} ; do +for npr in {1..10} ; do num=$(printf "%02d" "$npr") prog="a$num.out" if [ -f $prog ]; then