Task 5 is changed

This commit is contained in:
AZEN-SGG 2025-05-22 18:52:04 +03:00
parent e5b2c01295
commit 36497ec462
50 changed files with 1007904 additions and 144 deletions

View file

@ -27,10 +27,21 @@ void delete_list (node * head)
}
}
void delete_nodes (node *head, const int count)
{
for (int i = 0; i < count; ++i)
{
node *temp = head;
head = head->next;
delete_node(temp);
}
}
io_status read_list (node **list, const char *filename)
{
FILE *fp = 0;
char *string, buf[LEN_STR];
char *string, buf[LEN_STR] = {0};
node *head, *lunit, *unit;
head = lunit = unit = NULL;
@ -40,6 +51,7 @@ io_status read_list (node **list, const char *filename)
while (fgets(buf, LEN_STR, fp))
{
int len = strcspn(buf, "\n");
unit = (node *)malloc(sizeof(node));
if (!unit) {
fclose(fp);
@ -50,8 +62,8 @@ io_status read_list (node **list, const char *filename)
unit->next = NULL;
buf[strcspn(buf, "\n")] = '\0';
string = strdup(buf);
buf[len] = '\0';
string = (char *)malloc((len+1) * sizeof(char));
if (!string) {
fclose(fp);
free(unit);
@ -60,6 +72,8 @@ io_status read_list (node **list, const char *filename)
return ERR_MEM;
}
strcpy(string, buf);
unit->string = string;
if (!lunit)
head = unit;

View file

@ -4,8 +4,17 @@
#include "node.h"
#include "status.h"
int get_length (node * head);
void delete_list (node * head);
#include <stdlib.h>
static inline void delete_node (node *head)
{
free(head->string);
free(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);

View file

@ -27,10 +27,21 @@ void delete_list (node * head)
}
}
void delete_nodes (node *head, const int count)
{
for (int i = 0; i < count; ++i)
{
node *temp = head;
head = head->next;
delete_node(temp);
}
}
io_status read_list (node **list, const char *filename)
{
FILE *fp = 0;
char *string, buf[LEN_STR];
char *string, buf[LEN_STR] = {0};
node *head, *lunit, *unit;
head = lunit = unit = NULL;
@ -40,6 +51,7 @@ io_status read_list (node **list, const char *filename)
while (fgets(buf, LEN_STR, fp))
{
int len = strcspn(buf, "\n");
unit = (node *)malloc(sizeof(node));
if (!unit) {
fclose(fp);
@ -50,8 +62,8 @@ io_status read_list (node **list, const char *filename)
unit->next = NULL;
buf[strcspn(buf, "\n")] = '\0';
string = strdup(buf);
buf[len] = '\0';
string = (char *)malloc((len+1) * sizeof(char));
if (!string) {
fclose(fp);
free(unit);
@ -60,6 +72,8 @@ io_status read_list (node **list, const char *filename)
return ERR_MEM;
}
strcpy(string, buf);
unit->string = string;
if (!lunit)
head = unit;

View file

@ -4,8 +4,17 @@
#include "node.h"
#include "status.h"
int get_length (node * head);
void delete_list (node * head);
#include <stdlib.h>
static inline void delete_node (node *head)
{
free(head->string);
free(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);

View file

@ -0,0 +1,8 @@
a
b
a
c
d
a
f
g

View file

@ -27,10 +27,21 @@ void delete_list (node * head)
}
}
void delete_nodes (node *head, const int count)
{
for (int i = 0; i < count; ++i)
{
node *temp = head;
head = head->next;
delete_node(temp);
}
}
io_status read_list (node **list, const char *filename)
{
FILE *fp = 0;
char *string, buf[LEN_STR];
char *string, buf[LEN_STR] = {0};
node *head, *lunit, *unit;
head = lunit = unit = NULL;
@ -40,6 +51,7 @@ io_status read_list (node **list, const char *filename)
while (fgets(buf, LEN_STR, fp))
{
int len = strcspn(buf, "\n");
unit = (node *)malloc(sizeof(node));
if (!unit) {
fclose(fp);
@ -50,8 +62,8 @@ io_status read_list (node **list, const char *filename)
unit->next = NULL;
buf[strcspn(buf, "\n")] = '\0';
string = strdup(buf);
buf[len] = '\0';
string = (char *)malloc((len+1) * sizeof(char));
if (!string) {
fclose(fp);
free(unit);
@ -60,6 +72,8 @@ io_status read_list (node **list, const char *filename)
return ERR_MEM;
}
strcpy(string, buf);
unit->string = string;
if (!lunit)
head = unit;

View file

@ -4,8 +4,17 @@
#include "node.h"
#include "status.h"
int get_length (node * head);
void delete_list (node * head);
#include <stdlib.h>
static inline void delete_node (node *head)
{
free(head->string);
free(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);

View file

@ -0,0 +1 @@
single

View file

@ -27,10 +27,21 @@ void delete_list (node * head)
}
}
void delete_nodes (node *head, const int count)
{
for (int i = 0; i < count; ++i)
{
node *temp = head;
head = head->next;
delete_node(temp);
}
}
io_status read_list (node **list, const char *filename)
{
FILE *fp = 0;
char *string, buf[LEN_STR];
char *string, buf[LEN_STR] = {0};
node *head, *lunit, *unit;
head = lunit = unit = NULL;
@ -40,6 +51,7 @@ io_status read_list (node **list, const char *filename)
while (fgets(buf, LEN_STR, fp))
{
int len = strcspn(buf, "\n");
unit = (node *)malloc(sizeof(node));
if (!unit) {
fclose(fp);
@ -50,8 +62,8 @@ io_status read_list (node **list, const char *filename)
unit->next = NULL;
buf[strcspn(buf, "\n")] = '\0';
string = strdup(buf);
buf[len] = '\0';
string = (char *)malloc((len+1) * sizeof(char));
if (!string) {
fclose(fp);
free(unit);
@ -60,6 +72,8 @@ io_status read_list (node **list, const char *filename)
return ERR_MEM;
}
strcpy(string, buf);
unit->string = string;
if (!lunit)
head = unit;

View file

@ -4,8 +4,17 @@
#include "node.h"
#include "status.h"
int get_length (node * head);
void delete_list (node * head);
#include <stdlib.h>
static inline void delete_node (node *head)
{
free(head->string);
free(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);

View file

@ -11,6 +11,9 @@ int t4_solve (node *head)
last = head;
head = last->next;
if (!head)
return 0;
for (next = head->next; next; next = head->next)
{
int last_cmp = strcmp(head->string, last->string);

View file

@ -0,0 +1,8 @@
1
2
3
1
2
3
4
5

View file

@ -27,10 +27,21 @@ void delete_list (node * head)
}
}
void delete_nodes (node *head, const int count)
{
for (int i = 0; i < count; ++i)
{
node *temp = head;
head = head->next;
delete_node(temp);
}
}
io_status read_list (node **list, const char *filename)
{
FILE *fp = 0;
char *string, buf[LEN_STR];
char *string, buf[LEN_STR] = {0};
node *head, *lunit, *unit;
head = lunit = unit = NULL;
@ -40,6 +51,7 @@ io_status read_list (node **list, const char *filename)
while (fgets(buf, LEN_STR, fp))
{
int len = strcspn(buf, "\n");
unit = (node *)malloc(sizeof(node));
if (!unit) {
fclose(fp);
@ -50,8 +62,8 @@ io_status read_list (node **list, const char *filename)
unit->next = NULL;
buf[strcspn(buf, "\n")] = '\0';
string = strdup(buf);
buf[len] = '\0';
string = (char *)malloc((len+1) * sizeof(char));
if (!string) {
fclose(fp);
free(unit);
@ -60,6 +72,8 @@ io_status read_list (node **list, const char *filename)
return ERR_MEM;
}
strcpy(string, buf);
unit->string = string;
if (!lunit)
head = unit;

View file

@ -4,8 +4,17 @@
#include "node.h"
#include "status.h"
int get_length (node * head);
void delete_list (node * head);
#include <stdlib.h>
static inline void delete_node (node *head)
{
free(head->string);
free(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);

View file

@ -22,6 +22,9 @@ int t5_solve (node *head)
last = head->string;
}
if (maximum < count)
maximum = count;
return maximum;
}

View file

@ -27,10 +27,21 @@ void delete_list (node * head)
}
}
void delete_nodes (node *head, const int count)
{
for (int i = 0; i < count; ++i)
{
node *temp = head;
head = head->next;
delete_node(temp);
}
}
io_status read_list (node **list, const char *filename)
{
FILE *fp = 0;
char *string, buf[LEN_STR];
char *string, buf[LEN_STR] = {0};
node *head, *lunit, *unit;
head = lunit = unit = NULL;
@ -40,6 +51,7 @@ io_status read_list (node **list, const char *filename)
while (fgets(buf, LEN_STR, fp))
{
int len = strcspn(buf, "\n");
unit = (node *)malloc(sizeof(node));
if (!unit) {
fclose(fp);
@ -50,8 +62,8 @@ io_status read_list (node **list, const char *filename)
unit->next = NULL;
buf[strcspn(buf, "\n")] = '\0';
string = strdup(buf);
buf[len] = '\0';
string = (char *)malloc((len+1) * sizeof(char));
if (!string) {
fclose(fp);
free(unit);
@ -60,6 +72,8 @@ io_status read_list (node **list, const char *filename)
return ERR_MEM;
}
strcpy(string, buf);
unit->string = string;
if (!lunit)
head = unit;

View file

@ -4,8 +4,17 @@
#include "node.h"
#include "status.h"
int get_length (node * head);
void delete_list (node * head);
#include <stdlib.h>
static inline void delete_node (node *head)
{
free(head->string);
free(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);

View file

@ -27,10 +27,21 @@ void delete_list (node * head)
}
}
void delete_nodes (node *head, const int count)
{
for (int i = 0; i < count; ++i)
{
node *temp = head;
head = head->next;
delete_node(temp);
}
}
io_status read_list (node **list, const char *filename)
{
FILE *fp = 0;
char *string, buf[LEN_STR];
char *string, buf[LEN_STR] = {0};
node *head, *lunit, *unit;
head = lunit = unit = NULL;
@ -40,6 +51,7 @@ io_status read_list (node **list, const char *filename)
while (fgets(buf, LEN_STR, fp))
{
int len = strcspn(buf, "\n");
unit = (node *)malloc(sizeof(node));
if (!unit) {
fclose(fp);
@ -50,8 +62,8 @@ io_status read_list (node **list, const char *filename)
unit->next = NULL;
buf[strcspn(buf, "\n")] = '\0';
string = strdup(buf);
buf[len] = '\0';
string = (char *)malloc((len+1) * sizeof(char));
if (!string) {
fclose(fp);
free(unit);
@ -60,6 +72,8 @@ io_status read_list (node **list, const char *filename)
return ERR_MEM;
}
strcpy(string, buf);
unit->string = string;
if (!lunit)
head = unit;

View file

@ -4,8 +4,17 @@
#include "node.h"
#include "status.h"
int get_length (node * head);
void delete_list (node * head);
#include <stdlib.h>
static inline void delete_node (node *head)
{
free(head->string);
free(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);

View file

@ -27,10 +27,21 @@ void delete_list (node * head)
}
}
void delete_nodes (node *head, const int count)
{
for (int i = 0; i < count; ++i)
{
node *temp = head;
head = head->next;
delete_node(temp);
}
}
io_status read_list (node **list, const char *filename)
{
FILE *fp = 0;
char *string, buf[LEN_STR];
char *string, buf[LEN_STR] = {0};
node *head, *lunit, *unit;
head = lunit = unit = NULL;
@ -40,6 +51,7 @@ io_status read_list (node **list, const char *filename)
while (fgets(buf, LEN_STR, fp))
{
int len = strcspn(buf, "\n");
unit = (node *)malloc(sizeof(node));
if (!unit) {
fclose(fp);
@ -50,8 +62,8 @@ io_status read_list (node **list, const char *filename)
unit->next = NULL;
buf[strcspn(buf, "\n")] = '\0';
string = strdup(buf);
buf[len] = '\0';
string = (char *)malloc((len+1) * sizeof(char));
if (!string) {
fclose(fp);
free(unit);
@ -60,6 +72,8 @@ io_status read_list (node **list, const char *filename)
return ERR_MEM;
}
strcpy(string, buf);
unit->string = string;
if (!lunit)
head = unit;

View file

@ -4,8 +4,17 @@
#include "node.h"
#include "status.h"
int get_length (node * head);
void delete_list (node * head);
#include <stdlib.h>
static inline void delete_node (node *head)
{
free(head->string);
free(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);

View file

@ -22,14 +22,26 @@ void delete_list (node * head)
node *curr, *next;
for (curr = head; curr; curr = next) {
next = curr->next;
delete_node(curr);
free(curr->string);
free(curr);
}
}
void delete_nodes (node *head, const int count)
{
for (int i = 0; i < count; ++i)
{
node *temp = head;
head = head->next;
delete_node(temp);
}
}
io_status read_list (node **list, const char *filename)
{
FILE *fp = 0;
char *string, buf[LEN_STR];
char *string, buf[LEN_STR] = {0};
node *head, *lunit, *unit;
head = lunit = unit = NULL;
@ -39,6 +51,7 @@ io_status read_list (node **list, const char *filename)
while (fgets(buf, LEN_STR, fp))
{
int len = strcspn(buf, "\n");
unit = (node *)malloc(sizeof(node));
if (!unit) {
fclose(fp);
@ -49,8 +62,8 @@ io_status read_list (node **list, const char *filename)
unit->next = NULL;
buf[strcspn(buf, "\n")] = '\0';
string = strdup(buf);
buf[len] = '\0';
string = (char *)malloc((len+1) * sizeof(char));
if (!string) {
fclose(fp);
free(unit);
@ -59,6 +72,8 @@ io_status read_list (node **list, const char *filename)
return ERR_MEM;
}
strcpy(string, buf);
unit->string = string;
if (!lunit)
head = unit;

View file

@ -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);

1004879
2025.05.23/10Ex/input/big_a.txt Normal file

File diff suppressed because it is too large Load diff

View file

@ -17,6 +17,16 @@ int get_length (node * head)
return i;
}
void delete_list (node * head)
{
node *curr, *next;
for (curr = head; curr; curr = next) {
next = curr->next;
free(curr->string);
free(curr);
}
}
void delete_nodes (node *head, const int count)
{
for (int i = 0; i < count; ++i)
@ -28,19 +38,10 @@ void delete_nodes (node *head, const int count)
}
}
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];
char *string, buf[LEN_STR] = {0};
node *head, *lunit, *unit;
head = lunit = unit = NULL;
@ -50,6 +51,7 @@ io_status read_list (node **list, const char *filename)
while (fgets(buf, LEN_STR, fp))
{
int len = strcspn(buf, "\n");
unit = (node *)malloc(sizeof(node));
if (!unit) {
fclose(fp);
@ -60,8 +62,8 @@ io_status read_list (node **list, const char *filename)
unit->next = NULL;
buf[strcspn(buf, "\n")] = '\0';
string = strdup(buf);
buf[len] = '\0';
string = (char *)malloc((len+1) * sizeof(char));
if (!string) {
fclose(fp);
free(unit);
@ -70,6 +72,8 @@ io_status read_list (node **list, const char *filename)
return ERR_MEM;
}
strcpy(string, buf);
unit->string = string;
if (!lunit)
head = unit;

View file

@ -0,0 +1,10 @@
Задача: 1 | Файл: test6.txt | Ошибка: Программа завершилась с кодом 254
Задача: 2 | Файл: test6.txt | Ошибка: Программа завершилась с кодом 254
Задача: 3 | Файл: test6.txt | Ошибка: Программа завершилась с кодом 254
Задача: 4 | Файл: test6.txt | Ошибка: Программа завершилась с кодом 254
Задача: 5 | Файл: test6.txt | Ошибка: Программа завершилась с кодом 254
Задача: 6 | Файл: test6.txt | Ошибка: Программа завершилась с кодом 254
Задача: 7 | Файл: test6.txt | Ошибка: Программа завершилась с кодом 254
Задача: 8 | Файл: test6.txt | Ошибка: Программа завершилась с кодом 254
Задача: 9 | Файл: test6.txt | Ошибка: Программа завершилась с кодом 254
Задача: 10 | Файл: test6.txt | Ошибка: Программа завершилась с кодом 254

View file

@ -17,6 +17,16 @@ int get_length (node * head)
return i;
}
void delete_list (node * head)
{
node *curr, *next;
for (curr = head; curr; curr = next) {
next = curr->next;
free(curr->string);
free(curr);
}
}
void delete_nodes (node *head, const int count)
{
for (int i = 0; i < count; ++i)
@ -28,19 +38,10 @@ void delete_nodes (node *head, const int count)
}
}
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];
char *string, buf[LEN_STR] = {0};
node *head, *lunit, *unit;
head = lunit = unit = NULL;
@ -50,6 +51,7 @@ io_status read_list (node **list, const char *filename)
while (fgets(buf, LEN_STR, fp))
{
int len = strcspn(buf, "\n");
unit = (node *)malloc(sizeof(node));
if (!unit) {
fclose(fp);
@ -60,8 +62,8 @@ io_status read_list (node **list, const char *filename)
unit->next = NULL;
buf[strcspn(buf, "\n")] = '\0';
string = strdup(buf);
buf[len] = '\0';
string = (char *)malloc((len+1) * sizeof(char));
if (!string) {
fclose(fp);
free(unit);
@ -70,6 +72,8 @@ io_status read_list (node **list, const char *filename)
return ERR_MEM;
}
strcpy(string, buf);
unit->string = string;
if (!lunit)
head = unit;

1203
2025.05.23/dist/Krivoruchenko_SK/res.txt vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -11,6 +11,9 @@ int t4_solve (node *head)
last = head;
head = last->next;
if (!head)
return 0;
for (next = head->next; next; next = head->next)
{
int last_cmp = strcmp(head->string, last->string);

View file

@ -22,6 +22,9 @@ int t5_solve (node *head)
last = head->string;
}
if (maximum < count)
maximum = count;
return maximum;
}

File diff suppressed because it is too large Load diff

View file

@ -1,13 +0,0 @@
a
b
c
cd
ab
bc
cd
cd
cd
cd

39
2025.05.23/tests/bog_test.sh Executable file
View file

@ -0,0 +1,39 @@
script_name="$(basename "$0")"
script_path="$(realpath "$0")"
script_dir="$(dirname "$script_path")"
maxpr="100"
mkdir -p tests
if [ -f Makefile ]; then
echo "Компиляция..."
make clean
make
fi
outlog="$(pwd)/tests/out_$script_name.log"
errlog="$(pwd)/tests/err_$script_name.log"
rm -f "$outlog" "$errlog"
echo "Тест запущен..."
for npr in {1..10} ; do
num=$(printf "%02d" "$npr")
prog="a$num.out"
if [ -f $prog ]; then
for ntst in {1..15} ; do
cmd="./$prog $maxpr $script_dir/lists/$ntst"
echo "$cmd"
eval "$cmd"
done
fi
done >$outlog 2>$errlog
echo "Тест записан в $outlog"
echo "Ошибки записаны в $errlog"
echo "Тест завершен"
make clean

7
2025.05.23/tests/lists/1 Normal file
View file

@ -0,0 +1,7 @@
e
f
g
h
i
j
k

View file

@ -0,0 +1,8 @@
a1
ab2
abc3
abcd4
ba5
cba6
bac7
dabc8

View file

@ -0,0 +1,7 @@
a11
a21
a31
a22
a12
a23
a33

10
2025.05.23/tests/lists/12 Normal file
View file

@ -0,0 +1,10 @@
a12345
a1234
a123
a12
a1
b12345
b1234
b123
b12
b1

10
2025.05.23/tests/lists/13 Normal file
View file

@ -0,0 +1,10 @@
a
a
ab
ac
a
a
ad
ae
a
a

View file

@ -0,0 +1,6 @@
a1
a2
a3
ab1
ab2
ab3

10
2025.05.23/tests/lists/15 Normal file
View file

@ -0,0 +1,10 @@
a
aa
bb
cc
a
a
dd
ee
aaa
aaaa

6
2025.05.23/tests/lists/2 Normal file
View file

@ -0,0 +1,6 @@
a
a
ab
ab
abc
abc

6
2025.05.23/tests/lists/3 Normal file
View file

@ -0,0 +1,6 @@
a
a
ab
ab
abc
abc

6
2025.05.23/tests/lists/4 Normal file
View file

@ -0,0 +1,6 @@
a12345
a1234
a123
a12
a1
a

9
2025.05.23/tests/lists/5 Normal file
View file

@ -0,0 +1,9 @@
ab1
a2
ab3
a4
ab5
ab6
abc7
ab8

9
2025.05.23/tests/lists/6 Normal file
View file

@ -0,0 +1,9 @@
a
a
a
ab
ab
ab
ab
abc
abc

8
2025.05.23/tests/lists/7 Normal file
View file

@ -0,0 +1,8 @@
1
2
3
12
13
14
15
16

8
2025.05.23/tests/lists/8 Normal file
View file

@ -0,0 +1,8 @@
f1
f2
f3
g12
g123
g1234
h1
h2

6
2025.05.23/tests/lists/9 Normal file
View file

@ -0,0 +1,6 @@
a1
a2
a3
ab1
ab2
ab3

View file

@ -1,63 +0,0 @@
script_name="$(basename "$0")"
iter="1000"
eps="1e-14"
if [ "$#" -ne 1 ]; then
echo "Не указан как параметр номер программы"
exit 1
fi
num=$(printf "%02d" "$1")
prog="a$num.out"
mkdir -p tests
if [ -f Makefile ]; then
echo "Компиляция..."
make clean
make
fi
if [ ! -f $prog ]; then
echo "Отсутствует исполняемый файл... [$prog]"
echo "Завершение..."
exit 2
fi
outlog="$(pwd)/tests/out_a${num}_$script_name.log"
errlog="$(pwd)/tests/err_a${num}_$script_name.log"
rm -f "$outlog" "$errlog"
echo "Тест запущен..."
i=2
for (( k = 3 ; k < 7; k++ )); do
for (( a = -100 ; a < -40 ; a++ )); do
for (( b = -9 ; b < 10 ; b++ )); do
x="$(echo "$a / 10" | bc -l)"
y="$(echo "$b / 10" | bc -l)"
cmd="./$prog $poly_deg $x $y $eps $iter $k"
echo "$cmd"
echo "$i $(eval "$cmd")"
((i+=2))
done
done
for (( a = -9 ; a < 10 ; a++ )); do
for (( b = 11 ; b < 100 ; b++ )); do
x="$(echo "$a / 10" | bc -l)"
y="$(echo "$b / 10" | bc -l)"
cmd="./$prog $poly_deg $x $y $eps $iter $k"
echo "$cmd"
echo "$i $(eval "$cmd")"
((i+=2))
done
done
done >$outlog 2>$errlog
echo "Тест записан в $outlog"
echo "Ошибки записаны в $errlog"
echo "Тест завершен"

149
2025.05.23/tests/seva_test.sh Executable file
View file

@ -0,0 +1,149 @@
#!/bin/bash
# Скрипт для автотестирования задач 1-10 с однонаправленным списком строк
# Исполняемые файлы: a01.out, a02.out, ..., a10.out
# Ошибки сохраняются в error.txt
# Установка прав на исполнение
chmod +x a*.out
echo "Компилирую программу:"
make clean
make
echo "Программа скомпилирована"
# Очищаем файлы результатов и ошибок
> res.txt
> error.txt
# Функция для вывода разделителя
print_separator() {
echo "=================" >> res.txt
}
# Функция для записи ошибки
log_error() {
local task_num=$1
local test_file=$2
local message=$3
echo "Задача: $task_num | Файл: $test_file | Ошибка: $message" >> error.txt
}
# Функция для запуска теста с обработкой ошибок
run_test() {
local task_num=$1
local max_print=$2
local filename=$3
local binary="./a$(printf "%02d" $task_num).out"
# Проверяем существование исполняемого файла
if [ ! -f "$binary" ]; then
echo "Исполняемый файл $binary не найден!" >> res.txt
log_error $task_num $filename "Исполняемый файл $binary не найден"
return 1
fi
# Проверяем существование входного файла
if [ ! -f "$filename" ]; then
echo "Входной файл $filename не найден!" >> res.txt
log_error $task_num $filename "Входной файл не найден"
return 1
fi
# Запускаем программу и перехватываем ошибки
echo "Запуск: $binary $max_print $filename" >> res.txt
output=$(timeout 10s $binary $max_print $filename 2>&1)
status=$?
case $status in
0)
# Успешное выполнение
echo "$output" >> res.txt
;;
136|139)
# Ошибка SEGFAULT (SIGSEGV)
echo "ОШИБКА: SEGFAULT (нарушение сегментации)" >> res.txt
log_error $task_num $filename "SEGFAULT (нарушение сегментации)"
;;
8|136|137|139)
# FPE (SIGFPE) или другие сигналы
echo "ОШИБКА: FPE (ошибка вычисления с плавающей точкой)" >> res.txt
log_error $task_num $filename "FPE (ошибка вычисления с плавающей точкой)"
;;
124)
# Таймаут
echo "ОШИБКА: Таймаут выполнения (программа зависла)" >> res.txt
log_error $task_num $filename "Таймаут выполнения (программа зависла)"
;;
*)
# Другие ошибки
echo "ОШИБКА: Программа завершилась с кодом $status" >> res.txt
log_error $task_num $filename "Программа завершилась с кодом $status"
;;
esac
}
test="test"
# Создаем тестовые файлы с данными
create_test_files() {
# Тестовый файл 1 - несколько строк разной длины
echo -e "apple\nbanana\napple\ncherry\ndate\napple\nfig\ngrape" > ${test}1.txt
# Тестовый файл 2 - строки с повторениями
echo -e "one\none\ntwo\ntwo\ntwo\nthree\nfour\nfour" > test2.txt
# Тестовый файл 3 - возрастающая последовательность
echo -e "a\nb\nc\nd\ne\nf\ng\nh" > test3.txt
# Тестовый файл 4 - убывающая последовательность
echo -e "h\ng\nf\ne\nd\nc\nb\na" > test4.txt
# Тестовый файл 5 - случайные строки
echo -e "cat\ndog\ncat\nbird\nfish\nbird\ndog\ncat" > test5.txt
# Тестовый файл 6 - пустой файл
echo -n "" > test6.txt
# Тестовый файл 7 - одна строка
echo "single" > test7.txt
# Тестовый файл 8 - длинные строки
echo -e "very_long_string_1234567890\nshort\nmedium_length_string_123" > test8.txt
}
delete_test_files() {
for n in {1..8} ; do
rm "${test}$n.txt"
done ;
}
# Создаем тестовые файлы
create_test_files
# Запуск тестов для всех задач (1-10)
for task_num in {1..10}; do
print_separator
echo "=== ЗАДАЧА $task_num ===" >> res.txt
print_separator
# Тестируем на всех тестовых файлах
for test_file in test{1..8}.txt; do
echo "Тестируемый файл: $test_file" >> res.txt
echo "Максимум выводимых элементов: 5" >> res.txt
run_test $task_num 5 $test_file
echo "" >> res.txt # Добавляем пустую строку между тестами
done
echo "" >> res.txt # Добавляем пустую строку между задачами
done
delete_test_files
make clean
# Выводим количество ошибок
error_count=$(wc -l < error.txt)
echo "Найдено ошибок: $error_count" | tee -a res.txt