Add dist and change make_dist

This commit is contained in:
AZEN-SGG 2025-05-19 20:33:04 +03:00
parent a5ffe19dd8
commit 50e9bb6d59
31 changed files with 996 additions and 1 deletions

View file

@ -0,0 +1,18 @@
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
OBJ_COMMON = io_node.o
NUMS = 1 2 3 4 5 6 7 8 9 10 11 12
OUTS = $(foreach n,$(NUMS),$(shell printf "a%02d.out\n" "$(n)"))
all: $(OUTS)
%.o: %.c
gcc -c $(FLAGS) $<
a%.out: main_%.o solve_%.o $(OBJ_COMMON)
gcc $(FLAGS) $^ -o $@ -lm
clean:
rm -f *.o *.out

View file

@ -0,0 +1,85 @@
#include "io_node.h"
#include "node.h"
#include "status.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int get_length (node * head)
{
node *curr;
int i = 0;
for (curr = head; curr; curr=curr->next)
i++;
return i;
}
void delete_list (node * head)
{
node *curr, *next;
for (curr = head; curr; curr = next) {
next = curr->next;
delete_node(curr);
}
}
io_status read_list (node **list, const char *filename)
{
FILE *fp = 0;
char *string, buf[LEN_STR];
node *head, *lunit, *unit;
head = lunit = unit = NULL;
if (!(fp = fopen(filename, "r")))
return ERR_OPEN;
while (fgets(buf, LEN_STR, fp))
{
unit = (node *)malloc(sizeof(node));
if (!unit) {
fclose(fp);
delete_list(head);
return ERR_MEM;
}
unit->next = NULL;
buf[strcspn(buf, "\n")] = '\0';
string = strdup(buf);
if (!string) {
fclose(fp);
free(unit);
delete_list(head);
return ERR_MEM;
}
unit->string = string;
if (!lunit)
head = unit;
else
lunit->next = unit;
lunit = unit;
}
if (!head)
return ERR_READ;
*list = head;
fclose(fp);
return SUCCESS;
}
void print_list (node *head, const int p)
{
for (int i = 0; head && i < p; head = head->next, i++)
printf("%s\n", head->string);
}

View file

@ -0,0 +1,20 @@
#ifndef IO_NODE_H
#define IO_NODE_H
#include "node.h"
#include "status.h"
#include <stdlib.h>
static inline void delete_node (node *head)
{
free(head->string);
free(head);
}
int get_length (node *head);
void delete_list (node *head);
io_status read_list (node **list, const char *filename);
void print_list (node *head, const int p);
#endif

View file

@ -0,0 +1,67 @@
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <float.h>
#include "solve_01.h"
#include "node.h"
#include "io_node.h"
#include "status.h"
/* ./a01.out p filename */
int main (int argc, char *argv[])
{
node *head;
char *name;
double t;
int p, res, task = 1;
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);
print_list(head, p);
t = clock();
res = t1_solve(head);
t = (clock() - t) / CLOCKS_PER_SEC;
delete_list(head);
if (res < 0) {
fprintf (stderr, "%s : Task = %d Undefined error Elapsed = %.2f\n", argv[0], task, t);
return -3;
} else {
fprintf (stdout, "%s : Task = %d Result = %d Elapsed = %.2f\n", argv[0], task, res, t);
return 0;
}
}

View file

@ -0,0 +1,67 @@
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <float.h>
#include "solve_02.h"
#include "node.h"
#include "io_node.h"
#include "status.h"
/* ./a02.out p filename */
int main (int argc, char *argv[])
{
node *head;
char *name;
double t;
int p, res, task = 2;
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);
print_list(head, p);
t = clock();
res = t2_solve(head);
t = (clock() - t) / CLOCKS_PER_SEC;
delete_list(head);
if (res < 0) {
fprintf (stderr, "%s : Task = %d Undefined error Elapsed = %.2f\n", argv[0], task, t);
return -3;
} else {
fprintf (stdout, "%s : Task = %d Result = %d Elapsed = %.2f\n", argv[0], task, res, t);
return 0;
}
}

View file

@ -0,0 +1,67 @@
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <float.h>
#include "solve_03.h"
#include "node.h"
#include "io_node.h"
#include "status.h"
/* ./a03.out p filename */
int main (int argc, char *argv[])
{
node *head;
char *name;
double t;
int p, res, task = 3;
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);
print_list(head, p);
t = clock();
res = t3_solve(head);
t = (clock() - t) / CLOCKS_PER_SEC;
delete_list(head);
if (res < 0) {
fprintf (stderr, "%s : Task = %d Undefined error Elapsed = %.2f\n", argv[0], task, t);
return -3;
} else {
fprintf (stdout, "%s : Task = %d Result = %d Elapsed = %.2f\n", argv[0], task, res, t);
return 0;
}
}

View file

@ -0,0 +1,67 @@
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <float.h>
#include "solve_04.h"
#include "node.h"
#include "io_node.h"
#include "status.h"
/* ./a04.out p filename */
int main (int argc, char *argv[])
{
node *head;
char *name;
double t;
int p, res, task = 4;
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);
print_list(head, p);
t = clock();
res = t4_solve(head);
t = (clock() - t) / CLOCKS_PER_SEC;
delete_list(head);
if (res < 0) {
fprintf (stderr, "%s : Task = %d Undefined error Elapsed = %.2f\n", argv[0], task, t);
return -3;
} else {
fprintf (stdout, "%s : Task = %d Result = %d Elapsed = %.2f\n", argv[0], task, res, t);
return 0;
}
}

View file

@ -0,0 +1,67 @@
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <float.h>
#include "solve_05.h"
#include "node.h"
#include "io_node.h"
#include "status.h"
/* ./a05.out p filename */
int main (int argc, char *argv[])
{
node *head;
char *name;
double t;
int p, res, task = 5;
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);
print_list(head, p);
t = clock();
res = t5_solve(head);
t = (clock() - t) / CLOCKS_PER_SEC;
delete_list(head);
if (res < 0) {
fprintf (stderr, "%s : Task = %d Undefined error Elapsed = %.2f\n", argv[0], task, t);
return -3;
} else {
fprintf (stdout, "%s : Task = %d Result = %d Elapsed = %.2f\n", argv[0], task, res, t);
return 0;
}
}

View file

@ -0,0 +1,67 @@
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <float.h>
#include "solve_06.h"
#include "node.h"
#include "io_node.h"
#include "status.h"
/* ./a06.out p filename */
int main (int argc, char *argv[])
{
node *head;
char *name;
double t;
int p, res, task = 6;
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);
print_list(head, p);
t = clock();
res = t6_solve(head);
t = (clock() - t) / CLOCKS_PER_SEC;
delete_list(head);
if (res < 0) {
fprintf (stderr, "%s : Task = %d Undefined error Elapsed = %.2f\n", argv[0], task, t);
return -3;
} else {
fprintf (stdout, "%s : Task = %d Result = %d Elapsed = %.2f\n", argv[0], task, res, t);
return 0;
}
}

View file

@ -0,0 +1,67 @@
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <float.h>
#include "solve_07.h"
#include "node.h"
#include "io_node.h"
#include "status.h"
/* ./a07.out p filename */
int main (int argc, char *argv[])
{
node *head;
char *name;
double t;
int p, res, task = 7;
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);
print_list(head, p);
t = clock();
res = t7_solve(head);
t = (clock() - t) / CLOCKS_PER_SEC;
delete_list(head);
if (res < 0) {
fprintf (stderr, "%s : Task = %d Undefined error Elapsed = %.2f\n", argv[0], task, t);
return -3;
} else {
fprintf (stdout, "%s : Task = %d Result = %d Elapsed = %.2f\n", argv[0], task, res, t);
return 0;
}
}

View file

@ -0,0 +1,67 @@
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <float.h>
#include "solve_08.h"
#include "node.h"
#include "io_node.h"
#include "status.h"
/* ./a08.out p filename */
int main (int argc, char *argv[])
{
node *head;
char *name;
double t;
int p, len, task = 8;
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 = t8_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;
}

14
2025.05.23/dist/Krivoruchenko_SK/node.h vendored Normal file
View file

@ -0,0 +1,14 @@
#ifndef NODE_H
#define NODE_H
#define LEN_STR 1234
struct _node;
typedef struct _node
{
char *string;
struct _node *next;
} node;
#endif

View file

@ -0,0 +1,23 @@
#include "solve_01.h"
#include "node.h"
#include <string.h>
int t1_solve (node *head)
{
char *maximum = head->string;
int count = 1;
for (head = head->next; head; head = head->next)
{
int cmp = strcmp(head->string, maximum);
if (cmp > 0) {
maximum = head->string;
count = 1;
} else if (!cmp)
count++;
}
return count;
}

View file

@ -0,0 +1,8 @@
#ifndef SOLVE_H
#define SOLVE_H
#include "node.h"
int t1_solve (node *head);
#endif

View file

@ -0,0 +1,20 @@
#include "solve_02.h"
#include "node.h"
#include <string.h>
int t2_solve (node *head)
{
char *last = head->string;
int count = 1;
for (head = head->next; head; head = head->next)
{
if (strcmp(head->string, last) > 0)
count++;
last = head->string;
}
return count;
}

View file

@ -0,0 +1,8 @@
#ifndef SOLVE_H
#define SOLVE_H
#include "node.h"
int t2_solve (node *head);
#endif

View file

@ -0,0 +1,32 @@
#include "solve_03.h"
#include "node.h"
#include <string.h>
int t3_solve (node *head)
{
char *last = head->string;
int count = 0, local = 1;
for (head = head->next; head; head = head->next)
{
int cmp = strcmp(head->string, last);
if (cmp < 0) {
if (local) {
count += local;
local = 0;
}
} else if (cmp == 0) {
if (local)
local++;
} else
local = 1;
last = head->string;
}
count += local;
return count;
}

View file

@ -0,0 +1,8 @@
#ifndef SOLVE_H
#define SOLVE_H
#include "node.h"
int t3_solve (node *head);
#endif

View file

@ -0,0 +1,40 @@
#include "solve_04.h"
#include "node.h"
#include <string.h>
int t4_solve (node *head)
{
char *last = head->string;
int maximum = 0, count = 0, local = 1, strict = 1;
for (head = head->next; head; head = head->next)
{
int cmp = strcmp(head->string, last);
if (cmp > 0) {
count += local;
local = 1;
strict = 1;
} else if (cmp < 0) {
if (!strict)
count += local;
if (maximum < count)
maximum = count;
count = 0;
local = 1;
strict = 0;
} else {
local++;
}
last = head->string;
}
if (!strict)
count += local;
if (maximum < count)
maximum = count;
return maximum;
}

View file

@ -0,0 +1,8 @@
#ifndef SOLVE_H
#define SOLVE_H
#include "node.h"
int t4_solve (node *head);
#endif

View file

@ -0,0 +1,27 @@
#include "solve_05.h"
#include "node.h"
#include <string.h>
int t5_solve (node *head)
{
char *last = head->string;
int maximum = 1, count = 1;
for (head = head->next; head; head = head->next)
{
if (strcmp(head->string, last) > 0)
count++;
else {
if (maximum < count)
maximum = count;
count = 1;
}
last = head->string;
}
return maximum;
}

View file

@ -0,0 +1,8 @@
#ifndef SOLVE_H
#define SOLVE_H
#include "node.h"
int t5_solve (node *head);
#endif

View file

@ -0,0 +1,20 @@
#include "solve_06.h"
#include "node.h"
#include <string.h>
int t6_solve (node *head)
{
char *last = head->string;
int count = 1;
for (head = head->next; head; head = head->next)
{
if (strcmp(head->string, last))
count++;
last = head->string;
}
return count;
}

View file

@ -0,0 +1,8 @@
#ifndef SOLVE_H
#define SOLVE_H
#include "node.h"
int t6_solve (node *head);
#endif

View file

@ -0,0 +1,28 @@
#include "solve_07.h"
#include "node.h"
#include <string.h>
int t7_solve (node *head)
{
char *last = head->string;
int maximum = 0, count = 1;
for (head = head->next; head; head = head->next)
{
if (strcmp(head->string, last))
count++;
else {
if (maximum < (count-1))
maximum = count-1;
count = 0;
}
last = head->string;
}
if (maximum < count)
maximum = count;
return maximum;
}

View file

@ -0,0 +1,8 @@
#ifndef SOLVE_H
#define SOLVE_H
#include "node.h"
int t7_solve (node *head);
#endif

View file

@ -0,0 +1,42 @@
#include "solve_08.h"
#include "node.h"
#include <string.h>
#include <stdlib.h>
node * t8_solve (node *head)
{
node *last = head;
node *curr, *next;
curr = head->next;
if (!curr)
return head;
while (strcmp(last->string, curr->string) >= 0) {
free(last->string);
free(last);
last = curr;
head = curr;
curr = curr->next;
if (!curr)
return head;
}
for (next = curr->next; next; next = curr->next)
{
if (strcmp(curr->string, next->string) >= 0) {
free(curr->string);
free(curr);
last->next = next;
} else
last = curr;
curr = next;
}
return head;
}

View file

@ -0,0 +1,8 @@
#ifndef SOLVE_H
#define SOLVE_H
#include "node.h"
node * t8_solve (node *head);
#endif

View file

@ -0,0 +1,16 @@
#ifndef STATUS_H
#define STATUS_H
#define ERR_MSG_MEM "Error: Not enough memory"
#define ERR_MSG_OPEN "Error: Cannot open file"
#define ERR_MSG_READ "Error: Cannot read file"
typedef enum
{
SUCCESS,
ERR_OPEN = -1,
ERR_READ = -2,
ERR_MEM = -3
} io_status;
#endif

0
scripts/fix-makefiles.sh Normal file → Executable file
View file

12
scripts/make_dist.sh Normal file → Executable file
View file

@ -31,6 +31,13 @@ cleanup_and_exit() {
exit 1
}
replace_in_file() {
local file="$1"
local num="$2"
sed -i -E "s|([\"'])solve\.h\1|\1solve_${num}.h\1|g" "$file"
}
# Проход по задачам
for num in "${tasks[@]}"; do
folder=$(printf "%02dEx" "$num")
@ -44,12 +51,15 @@ for num in "${tasks[@]}"; do
cleanup_and_exit "Файл $src не найден"
fi
base=$(basename "$file" .c)
base="${file%.*}"
ext="${file##*.}"
dest_file="$dest_dir/${base}_${folder:0:2}.$ext"
cp "$src" "$dest_file" || cleanup_and_exit "Ошибка копирования $src"
copied_files+=("$dest_file")
if [[ "$file" == "main.c" || "$file" == "solve.c" ]]; then
replace_in_file "$dest_file" "${folder:0:2}"
fi
done
done