Add dist
This commit is contained in:
parent
80daf08c78
commit
255ca54f41
12 changed files with 336 additions and 50 deletions
|
@ -7,72 +7,67 @@
|
||||||
|
|
||||||
node * t9_solve (node *head)
|
node * t9_solve (node *head)
|
||||||
{
|
{
|
||||||
node *last, *curr = head, *next,
|
int cmp_last, cmp_next;
|
||||||
*deleted = NULL, *last_cmp;
|
node *last, *curr, *next,
|
||||||
int cmp;
|
*deleted;
|
||||||
|
last=next=deleted=NULL;
|
||||||
|
cmp_last=cmp_next=0;
|
||||||
|
curr = head;
|
||||||
|
if (!curr)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
next = head->next;
|
for (next = curr->next; next; next = curr->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;)
|
|
||||||
{
|
{
|
||||||
last_cmp = curr;
|
|
||||||
|
|
||||||
last = curr;
|
|
||||||
curr = next;
|
|
||||||
next = curr->next;
|
|
||||||
|
|
||||||
if (deleted)
|
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 (
|
if ((cmp_last >= 0) && (cmp_next >= 0))
|
||||||
(strcmp(curr->string, next->string) >= 0) &&
|
{
|
||||||
(strcmp(curr->string, last_cmp->string) >= 0)
|
|
||||||
) {
|
|
||||||
if (deleted)
|
if (deleted)
|
||||||
delete_node(deleted);
|
delete_node(deleted);
|
||||||
deleted = curr;
|
deleted = curr;
|
||||||
|
if (last) {
|
||||||
last->next = next;
|
last->next = next;
|
||||||
curr = last;
|
curr = last;
|
||||||
} else {
|
} else {
|
||||||
|
head = next;
|
||||||
|
curr = NULL;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
if (deleted)
|
if (deleted)
|
||||||
delete_node(deleted);
|
delete_node(deleted);
|
||||||
deleted = NULL;
|
deleted = NULL;
|
||||||
}
|
}
|
||||||
|
last = curr;
|
||||||
|
curr = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deleted)
|
if (deleted)
|
||||||
last_cmp = deleted;
|
cmp_last = strcmp(curr->string, deleted->string);
|
||||||
|
else if (!last)
|
||||||
|
cmp_last = 1;
|
||||||
else
|
else
|
||||||
last_cmp = curr;
|
cmp_last = strcmp(curr->string, last->string);
|
||||||
|
|
||||||
if (strcmp(next->string, last_cmp->string) >= 0) {
|
if (cmp_last >= 0)
|
||||||
curr->next = NULL;
|
{
|
||||||
|
delete_node(curr);
|
||||||
delete_node(next);
|
if (last)
|
||||||
|
last->next = NULL;
|
||||||
|
else
|
||||||
|
head = NULL;
|
||||||
|
curr = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deleted)
|
if (deleted)
|
||||||
delete_node(deleted);
|
delete_node(deleted);
|
||||||
|
|
||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
BIN
2025.05.23/Krivoruchenko_SK.zip
Normal file
BIN
2025.05.23/Krivoruchenko_SK.zip
Normal file
Binary file not shown.
6
2025.05.23/dist/Krivoruchenko_SK/Makefile
vendored
6
2025.05.23/dist/Krivoruchenko_SK/Makefile
vendored
|
@ -2,17 +2,17 @@ FLAGS = -fstack-protector-all -W -Wall -Wextra -Wunused -Wcast-align -Werror -pe
|
||||||
|
|
||||||
OBJ_COMMON = io_node.o
|
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)"))
|
OUTS = $(foreach n,$(NUMS),$(shell printf "a%02d.out\n" "$(n)"))
|
||||||
|
|
||||||
all: $(OUTS)
|
all: $(OUTS)
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
gcc -c $(FLAGS) $<
|
-gcc -c $(FLAGS) $<
|
||||||
|
|
||||||
a%.out: main_%.o solve_%.o $(OBJ_COMMON)
|
a%.out: main_%.o solve_%.o $(OBJ_COMMON)
|
||||||
gcc $(FLAGS) $^ -o $@ -lm
|
-gcc $(FLAGS) $^ -o $@ -lm
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o *.out
|
rm -f *.o *.out
|
||||||
|
|
11
2025.05.23/dist/Krivoruchenko_SK/io_node.c
vendored
11
2025.05.23/dist/Krivoruchenko_SK/io_node.c
vendored
|
@ -17,6 +17,17 @@ int get_length (node * head)
|
||||||
return i;
|
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)
|
void delete_list (node * head)
|
||||||
{
|
{
|
||||||
node *curr, *next;
|
node *curr, *next;
|
||||||
|
|
1
2025.05.23/dist/Krivoruchenko_SK/io_node.h
vendored
1
2025.05.23/dist/Krivoruchenko_SK/io_node.h
vendored
|
@ -13,6 +13,7 @@ static inline void delete_node (node *head)
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_length (node *head);
|
int get_length (node *head);
|
||||||
|
void delete_nodes (node *head, const int count);
|
||||||
void delete_list (node *head);
|
void delete_list (node *head);
|
||||||
io_status read_list (node **list, const char *filename);
|
io_status read_list (node **list, const char *filename);
|
||||||
void print_list (node *head, const int p);
|
void print_list (node *head, const int p);
|
||||||
|
|
67
2025.05.23/dist/Krivoruchenko_SK/main_09.c
vendored
Normal file
67
2025.05.23/dist/Krivoruchenko_SK/main_09.c
vendored
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
67
2025.05.23/dist/Krivoruchenko_SK/main_10.c
vendored
Normal file
67
2025.05.23/dist/Krivoruchenko_SK/main_10.c
vendored
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
73
2025.05.23/dist/Krivoruchenko_SK/solve_09.c
vendored
Normal file
73
2025.05.23/dist/Krivoruchenko_SK/solve_09.c
vendored
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
#include "solve_09.h"
|
||||||
|
#include "node.h"
|
||||||
|
#include "io_node.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
8
2025.05.23/dist/Krivoruchenko_SK/solve_09.h
vendored
Normal file
8
2025.05.23/dist/Krivoruchenko_SK/solve_09.h
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef SOLVE_H
|
||||||
|
#define SOLVE_H
|
||||||
|
|
||||||
|
#include "node.h"
|
||||||
|
|
||||||
|
node * t9_solve (node *head);
|
||||||
|
|
||||||
|
#endif
|
56
2025.05.23/dist/Krivoruchenko_SK/solve_10.c
vendored
Normal file
56
2025.05.23/dist/Krivoruchenko_SK/solve_10.c
vendored
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
#include "solve_10.h"
|
||||||
|
#include "node.h"
|
||||||
|
#include "io_node.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
8
2025.05.23/dist/Krivoruchenko_SK/solve_10.h
vendored
Normal file
8
2025.05.23/dist/Krivoruchenko_SK/solve_10.h
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef SOLVE_H
|
||||||
|
#define SOLVE_H
|
||||||
|
|
||||||
|
#include "node.h"
|
||||||
|
|
||||||
|
node * t10_solve (node *head);
|
||||||
|
|
||||||
|
#endif
|
|
@ -19,7 +19,7 @@ rm -f "$outlog" "$errlog"
|
||||||
|
|
||||||
echo "Тест запущен..."
|
echo "Тест запущен..."
|
||||||
|
|
||||||
for npr in {1..7} ; do
|
for npr in {1..10} ; do
|
||||||
num=$(printf "%02d" "$npr")
|
num=$(printf "%02d" "$npr")
|
||||||
prog="a$num.out"
|
prog="a$num.out"
|
||||||
if [ -f $prog ]; then
|
if [ -f $prog ]; then
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue