Added last three homeworks

This commit is contained in:
AZEN-SGG 2025-03-02 14:38:34 +03:00
parent f7b2367bc4
commit 0e3d948c9f
363 changed files with 18214 additions and 0 deletions

View file

@ -0,0 +1,8 @@
all: main.o array.o
gcc main.o array.o -o a01.out && rm *.o
main.o: main.c
gcc -c main.c
array.o: array.c
gcc -c array.c

View file

@ -0,0 +1,71 @@
#include "array.h"
io_status process_s(const char * s, char * s1, char * s2, const size_t len_s) {
size_t i;
int j;
for (i = 0, j = 0; i < len_s; ++i) {
if (s[i] == '\\') {
if (i + 1 == len_s) return ERROR_PATTERN;
else {
s1[j] = 0;
s2[j++] = s[++i];
}
} else if ((s[i] == '^') && (i == 0)) {
s1[j] = '1';
s2[j++] = s[++i];
} else {
s1[j] = '0';
s2[j++] = s[i];
}
}
s2[j] = '\0';
return SUCCESS;
}
io_status process_file(const char * f_in, const char * f_out, const char * s1, const char * s2, int * r) {
FILE * fp = fopen(f_in, "r");
if (!fp) return ERROR_OPEN;
else {
char buf[LEN] = {0};
size_t len_s = strlen(s2);
FILE * fw = fopen(f_out, "w");
int i;
if (!fw) {fclose(fp); return ERROR_OPEN;}
for (i = 0; fgets(buf, sizeof(buf), fp);) {
size_t len_buf = strlen(buf);
bool is_approach = process_string(buf, s1, s2, len_s, len_buf);
if (is_approach)
{
i++;
if (buf[len_buf - 1] == '\n') buf[len_buf - 1] = '\0';
fprintf(fw, "%s\n", buf);
}
}
*r = i;
}
return SUCCESS;
}
bool process_string(const char * buf, const char * s1, const char * s2, const size_t len_s, const size_t len_buf) {
if (len_buf < len_s) return false;
if (s1[0] == '1') {
size_t i;
for (i = 0; i < len_s; ++i) {
if (buf[i] != s2[i]) return false;
}
} else {
char * s_pointer = strstr(buf, s2);
if (!s_pointer) return false;
}
return true;
}

View file

@ -0,0 +1,13 @@
#ifndef ARRAY_H
#define ARRAY_H
#include "io_status.h"
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
io_status process_s(const char * s, char * s1, char * s2, const size_t len_s);
io_status process_file(const char * f_in, const char * f_out, const char * s1, const char * s2, int * r);
bool process_string(const char * buf, const char * s1, const char * s2, const size_t len_s, const size_t len_buf);
#endif

View file

@ -0,0 +1,13 @@
#ifndef IO_STATUS_H
#define IO_STATUS_H
#define LEN 1234
typedef enum io_status_ {
SUCCESS,
ERROR_OPEN,
ERROR_READ,
ERROR_PATTERN,
} io_status;
#endif

View file

@ -0,0 +1,67 @@
#include <stdio.h>
#include <time.h>
#include "io_status.h"
#include "array.h"
io_status task1(const char* f_in, const char* f_out, const char* s, int* res);
io_status task1(const char* f_in, const char* f_out, const char* s, int* res)
{
if (s == NULL) return ERROR_PATTERN;
else
{
size_t len_s = strlen(s);
io_status status;
char s1[len_s + 1]; // т.к. требуется место для \0
char s2[len_s + 1];
memset(s1, 0, len_s + 1);
memset(s2, 0, len_s + 1);
status = process_s(s, s1, s2, len_s);
if (status != SUCCESS) return status;
else
{
return process_file(f_in, f_out, s1, s2, res);
}
}
}
int main(int argc, char* argv[])
{
int task = 1;
io_status ret;
const char* f_in = 0;
const char* f_out = 0;
const char* s = 0;
int res = 0;
double t;
if (argc != 4)
{
printf("Usage: %s <f_in> <f_out> <s>\n", argv[0]);
return 1;
}
f_in = argv[1];
f_out = argv[2];
s = argv[3];
t = clock();
ret = task1(f_in, f_out, s, &res);
t = (clock() - t) / CLOCKS_PER_SEC;
switch (ret)
{
case SUCCESS:
printf("%s : Task = %d Result = %d Elapsed = %.2f\n",
argv[0], task, res, t);
break;
case ERROR_OPEN:
printf("Can not open %s\n", f_out);
return 1;
case ERROR_READ:
printf("Can not read %s\n", f_out);
return 2;
case ERROR_PATTERN:
printf("Error in pattern %s\n", s);
return 3;
}
return 0;
}

38
2025.02.14/1Ex/Makefile Normal file
View file

@ -0,0 +1,38 @@
CFLAGS = -mfpmath=sse \
-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 \
-D_DEBUG -g \
-c
all: main.o array.o
gcc main.o array.o -lssp && del *.o
main.o: main.c
gcc $(CFLAGS) main.c
array.o: array.c
gcc $(CFLAGS) array.c

74
2025.02.14/1Ex/array.c Normal file
View file

@ -0,0 +1,74 @@
#include "array.h"
io_status process_s(const char * s, char * s1, char * s2, const size_t len_s) {
size_t i;
int j;
for (i = 0, j = 0; i < len_s; ++i) {
if (s[i] == '\\') {
if (i + 1 == len_s) return ERROR_PATTERN;
else {
s1[j] = 0;
s2[j++] = s[++i];
}
} else if ((s[i] == '^') && (i == 0)) {
s1[j] = '1';
s2[j++] = s[++i];
} else {
s1[j] = '0';
s2[j++] = s[i];
}
}
s2[j] = '\0';
return SUCCESS;
}
io_status process_file(const char * f_in, const char * f_out, const char * s1, const char * s2, int * r) {
FILE * fp = fopen(f_in, "r");
if (!fp) return ERROR_OPEN;
else {
char buf[LEN] = {0};
size_t len_s = strlen(s2);
FILE * fw = fopen(f_out, "w");
int i;
if (!fw) {fclose(fp); return ERROR_OPEN;}
for (i = 0; fgets(buf, sizeof(buf), fp);) {
size_t len_buf = strlen(buf);
bool is_approach = process_string(buf, s1, s2, len_s, len_buf);
if (is_approach)
{
i++;
if (buf[len_buf - 1] == '\n') buf[len_buf - 1] = '\0';
fprintf(fw, "%s\n", buf);
}
}
*r = i;
fclose(fw);
}
fclose(fp);
return SUCCESS;
}
bool process_string(const char * buf, const char * s1, const char * s2, const size_t len_s, const size_t len_buf) {
if (len_buf < len_s) return false;
if (s1[0] == '1') {
size_t i;
for (i = 0; i < len_s; ++i) {
if (buf[i] != s2[i]) return false;
}
} else {
char * s_pointer = strstr(buf, s2);
if (!s_pointer) return false;
}
return true;
}

13
2025.02.14/1Ex/array.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef ARRAY_H
#define ARRAY_H
#include "io_status.h"
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
io_status process_s(const char * s, char * s1, char * s2, const size_t len_s);
io_status process_file(const char * f_in, const char * f_out, const char * s1, const char * s2, int * r);
bool process_string(const char * buf, const char * s1, const char * s2, const size_t len_s, const size_t len_buf);
#endif

View file

@ -0,0 +1,13 @@
#ifndef IO_STATUS_H
#define IO_STATUS_H
#define LEN 1234
typedef enum io_status_ {
SUCCESS,
ERROR_OPEN,
ERROR_READ,
ERROR_PATTERN,
} io_status;
#endif

67
2025.02.14/1Ex/main.c Normal file
View file

@ -0,0 +1,67 @@
#include <stdio.h>
#include <time.h>
#include "io_status.h"
#include "array.h"
io_status task1(const char* f_in, const char* f_out, const char* s, int* res);
io_status task1(const char* f_in, const char* f_out, const char* s, int* res)
{
if (s == NULL) return ERROR_PATTERN;
else
{
size_t len_s = strlen(s);
io_status status;
char s1[len_s + 1]; // т.к. требуется место для \0
char s2[len_s + 1];
memset(s1, 0, len_s + 1);
memset(s2, 0, len_s + 1);
status = process_s(s, s1, s2, len_s);
if (status != SUCCESS) return status;
else
{
return process_file(f_in, f_out, s1, s2, res);
}
}
}
int main(int argc, char* argv[])
{
int task = 1;
io_status ret;
const char* f_in = 0;
const char* f_out = 0;
const char* s = 0;
int res = 0;
double t;
if (argc != 4)
{
printf("Usage: %s <f_in> <f_out> <s>\n", argv[0]);
return 1;
}
f_in = argv[1];
f_out = argv[2];
s = argv[3];
t = clock();
ret = task1(f_in, f_out, s, &res);
t = (clock() - t) / CLOCKS_PER_SEC;
switch (ret)
{
case SUCCESS:
printf("%s : Task = %d Result = %d Elapsed = %.2f\n",
argv[0], task, res, t);
break;
case ERROR_OPEN:
printf("Can not open %s\n", f_out);
return 1;
case ERROR_READ:
printf("Can not read %s\n", f_out);
return 2;
case ERROR_PATTERN:
printf("Error in pattern %s\n", s);
return 3;
}
return 0;
}

14
2025.02.14/1Ex/o.txt Normal file
View file

@ -0,0 +1,14 @@
abs
\abs
absababa
ahahabs
ahahahabsahhaha
^abs
ahahahabs$jajaja
ha\abss$hello what!
.abs
abs
?abs
aaaaaaaaaaaaabs
+abs+
absssssss

1
2025.02.14/1Ex/out.txt Normal file
View file

@ -0,0 +1 @@
a^bs haha

23
2025.02.14/1Ex/t.txt Normal file
View file

@ -0,0 +1,23 @@
abs
\abs
absababa
ahahabs
ahahahabsahhaha
^abs
ahahahabs$jajaja
ha\abss$hello what!
pbs
ubs
.abs
abs
pbt
ats
.b.
bs
bsaha
?abs
aaaaaaaaaaaaabs
+abs+
absssssss

View file

@ -0,0 +1,13 @@
Проверка на s:
- в конце есть \
abs\
- в конце есть \\
abs\\
- в начале есть ^
^abs
- в начале есть \^
- Есть \ и ^

View file

@ -0,0 +1,8 @@
all: main.o array.o
gcc main.o array.o -o a02.out && rm *.o
main.o: main.c
gcc -c main.c
array.o: array.c
gcc -c array.c

View file

@ -0,0 +1,75 @@
#include "array.h"
io_status process_s(const char * s, char * s1, char * s2, const size_t len_s) {
size_t i;
int j;
for (i = 0, j = 0; i < len_s; ++i) {
if (s[i] == '\\') {
if (i + 1 == len_s) return ERROR_PATTERN;
else {
s1[j] = 0;
s2[j++] = s[++i];
}
} else if ((s[i] == '$') && (i + 1 == len_s)) {
if (j != 0)
{
s1[j-1] = '1';
}
} else {
s1[j] = '0';
s2[j++] = s[i];
}
}
s2[j] = '\0';
return SUCCESS;
}
io_status process_file(const char * f_in, const char * f_out, const char * s1, const char * s2, int * r) {
FILE * fp = fopen(f_in, "r");
if (!fp) return ERROR_OPEN;
else {
char buf[LEN] = {0};
size_t len_s = strlen(s2);
FILE * fw = fopen(f_out, "w");
int i;
if (!fw) {fclose(fp); return ERROR_OPEN;}
for (i = 0; fgets(buf, sizeof(buf), fp);) {
size_t len_buf = strlen(buf);
bool is_approach;
if (buf[len_buf-1] == '\n') buf[--len_buf] = '\0';
is_approach = process_string(buf, s1, s2, len_s, len_buf);
if (is_approach)
{
i++;
if (buf[len_buf - 1] == '\n') buf[len_buf - 1] = '\0';
fprintf(fw, "%s\n", buf);
}
}
*r = i;
}
return SUCCESS;
}
bool process_string(const char * buf, const char * s1, const char * s2, const size_t len_s, const size_t len_buf) {
if (len_buf < len_s) return false;
if (s1[len_s - 1] == '1') {
size_t i;
for (i = len_buf-1; i > len_buf-len_s-1; --i) {
if (buf[i] != s2[i-(len_buf-len_s)]) return false;
}
} else {
char * s_pointer = strstr(buf, s2);
if (!s_pointer) return false;
}
return true;
}

View file

@ -0,0 +1,13 @@
#ifndef ARRAY_H
#define ARRAY_H
#include "io_status.h"
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
io_status process_s(const char * s, char * s1, char * s2, const size_t len_s);
io_status process_file(const char * f_in, const char * f_out, const char * s1, const char * s2, int * r);
bool process_string(const char * buf, const char * s1, const char * s2, const size_t len_s, const size_t len_buf);
#endif

View file

@ -0,0 +1,13 @@
#ifndef IO_STATUS_H
#define IO_STATUS_H
#define LEN 1234
typedef enum io_status_ {
SUCCESS,
ERROR_OPEN,
ERROR_READ,
ERROR_PATTERN,
} io_status;
#endif

View file

@ -0,0 +1,67 @@
#include <stdio.h>
#include <time.h>
#include "io_status.h"
#include "array.h"
io_status task1(const char* f_in, const char* f_out, const char* s, int* res);
io_status task1(const char* f_in, const char* f_out, const char* s, int* res)
{
if (s == NULL) return ERROR_PATTERN;
else
{
size_t len_s = strlen(s);
io_status status;
char s1[len_s + 1]; // т.к. требуется место для \0
char s2[len_s + 1];
memset(s1, 0, len_s + 1);
memset(s2, 0, len_s + 1);
status = process_s(s, s1, s2, len_s);
if (status != SUCCESS) return status;
else
{
return process_file(f_in, f_out, s1, s2, res);
}
}
}
int main(int argc, char* argv[])
{
int task = 1;
io_status ret;
const char* f_in = 0;
const char* f_out = 0;
const char* s = 0;
int res = 0;
double t;
if (argc != 4)
{
printf("Usage: %s <f_in> <f_out> <s>\n", argv[0]);
return 1;
}
f_in = argv[1];
f_out = argv[2];
s = argv[3];
t = clock();
ret = task1(f_in, f_out, s, &res);
t = (clock() - t) / CLOCKS_PER_SEC;
switch (ret)
{
case SUCCESS:
printf("%s : Task = %d Result = %d Elapsed = %.2f\n",
argv[0], task, res, t);
break;
case ERROR_OPEN:
printf("Can not open %s\n", f_out);
return 1;
case ERROR_READ:
printf("Can not read %s\n", f_out);
return 2;
case ERROR_PATTERN:
printf("Error in pattern %s\n", s);
return 3;
}
return 0;
}

38
2025.02.14/2Ex/Makefile Normal file
View file

@ -0,0 +1,38 @@
CFLAGS = -mfpmath=sse \
-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 \
-D_DEBUG -g \
-c
all: main.o array.o
gcc main.o array.o -lssp && del *.o
main.o: main.c
gcc $(CFLAGS) main.c
array.o: array.c
gcc $(CFLAGS) array.c

78
2025.02.14/2Ex/array.c Normal file
View file

@ -0,0 +1,78 @@
#include "array.h"
io_status process_s(const char * s, char * s1, char * s2, const size_t len_s) {
size_t i;
int j;
for (i = 0, j = 0; i < len_s; ++i) {
if (s[i] == '\\') {
if (i + 1 == len_s) return ERROR_PATTERN;
else {
s1[j] = 0;
s2[j++] = s[++i];
}
} else if ((s[i] == '$') && (i + 1 == len_s)) {
if (j != 0)
{
s1[j-1] = '1';
}
} else {
s1[j] = '0';
s2[j++] = s[i];
}
}
s2[j] = '\0';
return SUCCESS;
}
io_status process_file(const char * f_in, const char * f_out, const char * s1, const char * s2, int * r) {
FILE * fp = fopen(f_in, "r");
if (!fp) return ERROR_OPEN;
else {
char buf[LEN] = {0};
size_t len_s = strlen(s2);
FILE * fw = fopen(f_out, "w");
int i;
if (!fw) {fclose(fp); return ERROR_OPEN;}
for (i = 0; fgets(buf, sizeof(buf), fp);) {
size_t len_buf = strlen(buf);
bool is_approach;
if (buf[len_buf-1] == '\n') buf[--len_buf] = '\0';
is_approach = process_string(buf, s1, s2, len_s, len_buf);
if (is_approach)
{
i++;
if (buf[len_buf - 1] == '\n') buf[len_buf - 1] = '\0';
fprintf(fw, "%s\n", buf);
}
}
*r = i;
fclose(fw);
}
fclose(fp);
return SUCCESS;
}
bool process_string(const char * buf, const char * s1, const char * s2, const size_t len_s, const size_t len_buf) {
if (len_buf < len_s) return false;
if (s1[len_s - 1] == '1') {
size_t i;
for (i = len_buf-1; i > len_buf-len_s-1; --i) {
if (buf[i] != s2[i-(len_buf-len_s)]) return false;
}
} else {
char * s_pointer = strstr(buf, s2);
if (!s_pointer) return false;
}
return true;
}

13
2025.02.14/2Ex/array.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef ARRAY_H
#define ARRAY_H
#include "io_status.h"
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
io_status process_s(const char * s, char * s1, char * s2, const size_t len_s);
io_status process_file(const char * f_in, const char * f_out, const char * s1, const char * s2, int * r);
bool process_string(const char * buf, const char * s1, const char * s2, const size_t len_s, const size_t len_buf);
#endif

View file

@ -0,0 +1,13 @@
#ifndef IO_STATUS_H
#define IO_STATUS_H
#define LEN 1234
typedef enum io_status_ {
SUCCESS,
ERROR_OPEN,
ERROR_READ,
ERROR_PATTERN,
} io_status;
#endif

67
2025.02.14/2Ex/main.c Normal file
View file

@ -0,0 +1,67 @@
#include <stdio.h>
#include <time.h>
#include "io_status.h"
#include "array.h"
io_status task2(const char* f_in, const char* f_out, const char* s, int* res);
io_status task2(const char* f_in, const char* f_out, const char* s, int* res)
{
if (s == NULL) return ERROR_PATTERN;
else
{
size_t len_s = strlen(s);
io_status status;
char s1[len_s + 1]; // т.к. требуется место для \0
char s2[len_s + 1];
memset(s1, 0, len_s + 1);
memset(s2, 0, len_s + 1);
status = process_s(s, s1, s2, len_s);
if (status != SUCCESS) return status;
else
{
return process_file(f_in, f_out, s1, s2, res);
}
}
}
int main(int argc, char* argv[])
{
int task = 2;
io_status ret;
const char* f_in = 0;
const char* f_out = 0;
const char* s = 0;
int res = 0;
double t;
if (argc != 4)
{
printf("Usage: %s <f_in> <f_out> <s>\n", argv[0]);
return 1;
}
f_in = argv[1];
f_out = argv[2];
s = argv[3];
t = clock();
ret = task2(f_in, f_out, s, &res);
t = (clock() - t) / CLOCKS_PER_SEC;
switch (ret)
{
case SUCCESS:
printf("%s : Task = %d Result = %d Elapsed = %.2f\n",
argv[0], task, res, t);
break;
case ERROR_OPEN:
printf("Can not open %s\n", f_out);
return 1;
case ERROR_READ:
printf("Can not read %s\n", f_out);
return 2;
case ERROR_PATTERN:
printf("Error in pattern %s\n", s);
return 3;
}
return 0;
}

14
2025.02.14/2Ex/o.txt Normal file
View file

@ -0,0 +1,14 @@
abs
\abs
absababa
ahahabs
ahahahabsahhaha
^abs
ahahahabs$jajaja
ha\abss$hello what!
.abs
abs
?abs
aaaaaaaaaaaaabs
+abs+
absssssss

23
2025.02.14/2Ex/t.txt Normal file
View file

@ -0,0 +1,23 @@
abs
\abs
absababa
ahahabs
ahahahabsahhaha
^abs
ahahahabs$jajaja
ha\abss$hello what!
pbs
ubs
.abs
abs
pbt
ats
.b.
bs
bsaha
?abs
aaaaaaaaaaaaabs
+abs+
absssssss

View file

@ -0,0 +1,21 @@
Проверка на s:
- в конце есть \
abs\
- в конце есть \\
abs\\
- в конце есть $
abs$
- в конце есть \$
abs\$
- Есть \ и $
\\abs\s\$\hello
- в строке один $
$
- дефолт
abs

View file

@ -0,0 +1,8 @@
all: main.o array.o
gcc main.o array.o -o "a03.out" && rm *.o
main.o: main.c
gcc -c main.c
array.o: array.c
gcc -c array.c

View file

@ -0,0 +1,125 @@
#include "array.h"
io_status process_s(const char* s, char* s1, char* s2, const size_t len_s)
{
size_t i;
int j;
for (i = 0, j = 0; i < len_s; ++i)
{
if (s[i] == '\\')
{
if (i + 1 == len_s) return ERROR_PATTERN;
else if ((i == 0) && (s[i + 1] == '<'))
{
s1[j] = '1';
s2[j++] = s[i += 2];
}
else
{
s1[j] = '0';
s2[j++] = s[++i];
}
}
else
{
s1[j] = '0';
s2[j++] = s[i];
}
}
s2[j] = '\0';
return SUCCESS;
}
io_status process_file(const char* f_in, const char* f_out, const char* s1, const char* s2, const char* t, int* r)
{
FILE* fp = fopen(f_in, "r");
if (!fp) return ERROR_OPEN;
else
{
char buf[LEN] = {0};
size_t len_s = strlen(s2);
FILE* fw = fopen(f_out, "w");
int i;
if (!fw)
{
fclose(fp);
return ERROR_OPEN;
}
for (i = 0; fgets(buf, sizeof(buf), fp);)
{
size_t len_buf = strlen(buf);
bool is_approach = process_string(buf, s1, s2, t, len_s, len_buf);
if (is_approach)
{
i++;
if (buf[len_buf - 1] == '\n') buf[len_buf - 1] = '\0';
fprintf(fw, "%s\n", buf);
}
}
*r = i;
}
return SUCCESS;
}
bool process_string(const char* buf, const char* s1, const char* s2, const char* t, const size_t len_s,
const size_t len_buf)
{
if (len_buf < len_s) return false;
else
{
if (s1[0] == '1')
{
size_t i, last_space = -1, per_sim = 0; // Percent of similarity
for (i = 0; i < len_buf; ++i)
{
if (is_space(buf[i], t))
{
last_space = i;
per_sim = 0;
}
else
{
if (buf[i] == s2[per_sim])
{
if ((i == last_space + 1) || (per_sim))
{
if (++per_sim == len_s)
{
return true;
}
}
}
else
{
per_sim = 0;
}
}
}
return false;
}
else
{
if (strstr(buf, s2)) return true;
else return false;
}
}
}
bool is_space(char symbol, const char* t)
{
int i;
for (i = 0; t[i] != '\0'; ++i)
{
if (t[i] == symbol) return true;
}
return false;
}

View file

@ -0,0 +1,14 @@
#ifndef ARRAY_H
#define ARRAY_H
#include "io_status.h"
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
io_status process_s(const char * s, char * s1, char * s2, const size_t len_s);
io_status process_file(const char * f_in, const char * f_out, const char * s1, const char * s2, const char * t, int * r);
bool process_string(const char * buf, const char * s1, const char * s2, const char * t, const size_t len_s, const size_t len_buf);
bool is_space(char symbol, const char * t);
#endif

View file

@ -0,0 +1,13 @@
#ifndef IO_STATUS_H
#define IO_STATUS_H
#define LEN 1234
typedef enum io_status_ {
SUCCESS,
ERROR_OPEN,
ERROR_READ,
ERROR_PATTERN,
} io_status;
#endif

View file

@ -0,0 +1,69 @@
#include <stdio.h>
#include <time.h>
#include "io_status.h"
#include "array.h"
io_status task3(const char* f_in, const char* f_out, const char* s, const char* t, int* res);
io_status task3(const char* f_in, const char* f_out, const char* s, const char* t, int* res)
{
if (s == NULL) return ERROR_PATTERN;
else
{
size_t len_s = strlen(s);
io_status status;
char s1[len_s + 1]; // т.к. требуется место для \0
char s2[len_s + 1];
memset(s1, 0, len_s + 1);
memset(s2, 0, len_s + 1);
status = process_s(s, s1, s2, len_s);
if (status != SUCCESS) return status;
else
{
return process_file(f_in, f_out, s1, s2, t, res);
}
}
}
int main(int argc, char* argv[])
{
int task = 3;
io_status ret;
const char* f_in = 0;
const char* f_out = 0;
const char* s = 0;
const char* spaces = 0;
int res = 0;
double t;
if (argc != 5)
{
printf("Usage: %s <f_in> <f_out> <s> <t>\n", argv[0]);
return 1;
}
f_in = argv[1];
f_out = argv[2];
s = argv[3];
spaces = argv[4];
t = clock();
ret = task3(f_in, f_out, s, spaces, &res);
t = (clock() - t) / CLOCKS_PER_SEC;
switch (ret)
{
case SUCCESS:
printf("%s : Task = %d Result = %d Elapsed = %.2f\n",
argv[0], task, res, t);
break;
case ERROR_OPEN:
printf("Can not open %s\n", f_out);
return 1;
case ERROR_READ:
printf("Can not read %s\n", f_out);
return 2;
case ERROR_PATTERN:
printf("Error in pattern %s\n", s);
return 3;
}
return 0;
}

View file

@ -0,0 +1,2 @@
sasobsomcsome
hsome

View file

@ -0,0 +1,2 @@
sasobsomcsome
hsome

38
2025.02.14/3Ex/Makefile Normal file
View file

@ -0,0 +1,38 @@
CFLAGS = -mfpmath=sse \
-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 \
-D_DEBUG -g \
-c
all: main.o array.o
gcc main.o array.o -lssp && del *.o
main.o: main.c
gcc $(CFLAGS) main.c
array.o: array.c
gcc $(CFLAGS) array.c

128
2025.02.14/3Ex/array.c Normal file
View file

@ -0,0 +1,128 @@
#include "array.h"
io_status process_s(const char* s, char* s1, char* s2, const size_t len_s)
{
size_t i;
int j;
for (i = 0, j = 0; i < len_s; ++i)
{
if (s[i] == '\\')
{
if (i + 1 == len_s) return ERROR_PATTERN;
else if ((i == 0) && (s[i + 1] == '<'))
{
s1[j] = '1';
i++;
}
else
{
if (s1[j] != '1') s1[j] = '0';
s2[j++] = s[++i];
}
}
else
{
if (s1[j] != '1') s1[j] = '0';
s2[j++] = s[i];
}
}
s2[j] = '\0';
return SUCCESS;
}
io_status process_file(const char* f_in, const char* f_out, const char* s1, const char* s2, const char* t, int* r)
{
FILE* fp = fopen(f_in, "r");
if (!fp) return ERROR_OPEN;
else
{
char buf[LEN] = {0};
size_t len_s = strlen(s2);
FILE* fw = fopen(f_out, "w");
int i;
if (!fw)
{
fclose(fp);
return ERROR_OPEN;
}
for (i = 0; fgets(buf, sizeof(buf), fp);)
{
size_t len_buf = strlen(buf);
bool is_approach = process_string(buf, s1, s2, t, len_s, len_buf);
if (is_approach)
{
i++;
if ((len_buf > 0) && (buf[len_buf - 1] == '\n')) buf[len_buf - 1] = '\0';
fprintf(fw, "%s\n", buf);
}
}
*r = i;
fclose(fw);
}
fclose(fp);
return SUCCESS;
}
bool process_string(const char* buf, const char* s1, const char* s2, const char* t, const size_t len_s,
const size_t len_buf)
{
if (len_buf < len_s) return false;
else
{
if (s1[0] == '1')
{
int last_space = -1, i;
size_t per_sim = 0; // Percent of similarity
for (i = 0; i < (int)len_buf; ++i)
{
if (is_space(buf[i], t))
{
last_space = i;
per_sim = 0;
}
else
{
if (buf[i] == s2[per_sim])
{
if ((i == last_space + 1) || (per_sim))
{
if (++per_sim == len_s)
{
return true;
}
}
}
else
{
per_sim = 0;
}
}
}
return false;
}
else
{
if (strstr(buf, s2)) return true;
else return false;
}
}
}
bool is_space(char symbol, const char* t)
{
int i;
for (i = 0; t[i] != '\0'; ++i)
{
if (t[i] == symbol) return true;
}
return false;
}

14
2025.02.14/3Ex/array.h Normal file
View file

@ -0,0 +1,14 @@
#ifndef ARRAY_H
#define ARRAY_H
#include "io_status.h"
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
io_status process_s(const char * s, char * s1, char * s2, const size_t len_s);
io_status process_file(const char * f_in, const char * f_out, const char * s1, const char * s2, const char * t, int * r);
bool process_string(const char * buf, const char * s1, const char * s2, const char * t, const size_t len_s, const size_t len_buf);
bool is_space(char symbol, const char * t);
#endif

View file

@ -0,0 +1,13 @@
#ifndef IO_STATUS_H
#define IO_STATUS_H
#define LEN 1234
typedef enum io_status_ {
SUCCESS,
ERROR_OPEN,
ERROR_READ,
ERROR_PATTERN,
} io_status;
#endif

69
2025.02.14/3Ex/main.c Normal file
View file

@ -0,0 +1,69 @@
#include <stdio.h>
#include <time.h>
#include "io_status.h"
#include "array.h"
io_status task3(const char* f_in, const char* f_out, const char* s, const char* t, int* res);
io_status task3(const char* f_in, const char* f_out, const char* s, const char* t, int* res)
{
if (s == NULL) return ERROR_PATTERN;
else
{
size_t len_s = strlen(s);
io_status status;
char s1[len_s + 1]; // т.к. требуется место для \0
char s2[len_s + 1];
memset(s1, 0, len_s + 1);
memset(s2, 0, len_s + 1);
status = process_s(s, s1, s2, len_s);
if (status != SUCCESS) return status;
else
{
return process_file(f_in, f_out, s1, s2, t, res);
}
}
}
int main(int argc, char* argv[])
{
int task = 3;
io_status ret;
const char* f_in = 0;
const char* f_out = 0;
const char* s = 0;
const char* spaces = 0;
int res = 0;
double t;
if (argc != 5)
{
printf("Usage: %s <f_in> <f_out> <s> <t>\n", argv[0]);
return 1;
}
f_in = argv[1];
f_out = argv[2];
s = argv[3];
spaces = argv[4];
t = clock();
ret = task3(f_in, f_out, s, spaces, &res);
t = (clock() - t) / CLOCKS_PER_SEC;
switch (ret)
{
case SUCCESS:
printf("%s : Task = %d Result = %d Elapsed = %.2f\n",
argv[0], task, res, t);
break;
case ERROR_OPEN:
printf("Can not open %s\n", f_out);
return 1;
case ERROR_READ:
printf("Can not read %s\n", f_out);
return 2;
case ERROR_PATTERN:
printf("Error in pattern %s\n", s);
return 3;
}
return 0;
}

4
2025.02.14/3Ex/o.txt Normal file
View file

@ -0,0 +1,4 @@
somePalongPway
some
howPsomePitPbe
howPsomething

28
2025.02.14/3Ex/t.txt Normal file
View file

@ -0,0 +1,28 @@
abs
\abs
absababa
ahahabs
ahahahabsahhaha
^abs
ahahahabs$jajaja
ha\abss$hello what!
pbs
ubs
.abs
abs
pbt
ats
.b.
bs
bsaha
?abs
aaaaaaaaaaaaabs
+abs+
absssssss
abs*
somePalongPway
some
howPsomePitPbe
howPsomething
whyPanysome

View file

@ -0,0 +1,12 @@
Дефолт: Проверить что находит по паттерну:
{
"pattern": "some",
"text": "some text"
}
Проверка работы \<:
{
"pattern": "\<some",
"spaces": "abc"
"text": "sasobsomcsome"
}

38
2025.02.14/4Ex/Makefile Normal file
View file

@ -0,0 +1,38 @@
CFLAGS = -mfpmath=sse \
-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 \
-D_DEBUG -g \
-c
all: main.o array.o
gcc main.o array.o -lssp && del *.o
main.o: main.c
gcc $(CFLAGS) main.c
array.o: array.c
gcc $(CFLAGS) array.c

135
2025.02.14/4Ex/array.c Normal file
View file

@ -0,0 +1,135 @@
#include "array.h"
io_status process_s(const char* s, char* s1, char* s2, const size_t len_s)
{
size_t i;
int j;
for (i = 0, j = 0; i < len_s; ++i)
{
if (s[i] == '\\')
{
if (i + 1 == len_s) return ERROR_PATTERN;
else if ((i == len_s - 2) && (s[i + 1] == '>'))
{
if (j > 0)
{
s1[j++-1] = '1';
} else
{
s1[j++] = '1';
}
}
else
{
s1[j] = '0';
s2[j++] = s[++i];
}
}
else
{
s1[j] = '0';
s2[j++] = s[i];
}
}
s2[j] = '\0';
return SUCCESS;
}
io_status process_file(const char* f_in, const char* f_out, const char* s1, const char* s2, const char* t, int* r)
{
FILE* fp = fopen(f_in, "r");
if (!fp) return ERROR_OPEN;
else
{
char buf[LEN] = {0};
size_t len_s = strlen(s2);
FILE* fw = fopen(f_out, "w");
int i;
if (!fw)
{
fclose(fp);
return ERROR_OPEN;
}
for (i = 0; fgets(buf, sizeof(buf), fp);)
{
size_t len_buf = strlen(buf);
bool is_approach;
if (buf[len_buf - 1] == '\n') buf[--len_buf] = '\0';
is_approach = process_string(buf, s1, s2, t, len_s, len_buf);
if (is_approach)
{
i++;
if (buf[len_buf - 1] == '\n') buf[len_buf - 1] = '\0';
fprintf(fw, "%s\n", buf);
}
}
*r = i;
fclose(fw);
}
fclose(fp);
return SUCCESS;
}
bool process_string(const char* buf, const char* s1, const char* s2, const char* t, const size_t len_s,
const size_t len_buf)
{
if (len_buf < len_s) return false;
else
{
if (s1[len_s - 1] == '1')
{
size_t i, last_space = len_buf, per_sim = len_s - 1; // Percent of similarity
for (i = len_buf - 1; i < i + 2; --i) // i < i + 2 - size_t всегда положительный -> закончится когда случится переход от -1 к -2, а они сильно больше 0
{
if (is_space(buf[i], t))
{
last_space = i;
per_sim = len_s - 1;
}
else
{
if (buf[i] == s2[per_sim])
{
if ((i == last_space - 1) || ((per_sim + 1) < len_s))
{
if (per_sim-- == 0)
{
return true;
}
}
}
else
{
per_sim = len_s - 1;
}
}
}
return false;
}
else
{
if (strstr(buf, s2)) return true;
else return false;
}
}
}
bool is_space(char symbol, const char* t)
{
int i;
for (i = 0; t[i] != '\0'; ++i)
{
if (t[i] == symbol) return true;
}
return false;
}

14
2025.02.14/4Ex/array.h Normal file
View file

@ -0,0 +1,14 @@
#ifndef ARRAY_H
#define ARRAY_H
#include "io_status.h"
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
io_status process_s(const char * s, char * s1, char * s2, const size_t len_s);
io_status process_file(const char * f_in, const char * f_out, const char * s1, const char * s2, const char * t, int * r);
bool process_string(const char * buf, const char * s1, const char * s2, const char * t, const size_t len_s, const size_t len_buf);
bool is_space(char symbol, const char * t);
#endif

View file

@ -0,0 +1,13 @@
#ifndef IO_STATUS_H
#define IO_STATUS_H
#define LEN 1234
typedef enum io_status_ {
SUCCESS,
ERROR_OPEN,
ERROR_READ,
ERROR_PATTERN,
} io_status;
#endif

69
2025.02.14/4Ex/main.c Normal file
View file

@ -0,0 +1,69 @@
#include <stdio.h>
#include <time.h>
#include "io_status.h"
#include "array.h"
io_status task4(const char* f_in, const char* f_out, const char* s, const char* t, int* res);
io_status task4(const char* f_in, const char* f_out, const char* s, const char* t, int* res)
{
if (s == NULL) return ERROR_PATTERN;
else
{
size_t len_s = strlen(s);
io_status status;
char s1[len_s + 1]; // т.к. требуется место для \0
char s2[len_s + 1];
memset(s1, 0, len_s + 1);
memset(s2, 0, len_s + 1);
status = process_s(s, s1, s2, len_s);
if (status != SUCCESS) return status;
else
{
return process_file(f_in, f_out, s1, s2, t, res);
}
}
}
int main(int argc, char* argv[])
{
int task = 4;
io_status ret;
const char* f_in = 0;
const char* f_out = 0;
const char* s = 0;
const char* spaces = 0;
int res = 0;
double t;
if (argc != 5)
{
printf("Usage: %s <f_in> <f_out> <s> <t>\n", argv[0]);
return 1;
}
f_in = argv[1];
f_out = argv[2];
s = argv[3];
spaces = argv[4];
t = clock();
ret = task4(f_in, f_out, s, spaces, &res);
t = (clock() - t) / CLOCKS_PER_SEC;
switch (ret)
{
case SUCCESS:
printf("%s : Task = %d Result = %d Elapsed = %.2f\n",
argv[0], task, res, t);
break;
case ERROR_OPEN:
printf("Can not open %s\n", f_out);
return 1;
case ERROR_READ:
printf("Can not read %s\n", f_out);
return 2;
case ERROR_PATTERN:
printf("Error in pattern %s\n", s);
return 3;
}
return 0;
}

0
2025.02.14/4Ex/o.txt Normal file
View file

23
2025.02.14/4Ex/t.txt Normal file
View file

@ -0,0 +1,23 @@
abs
\abs
absababa
ahahabs
ahahahabsahhaha
^abs
ahahahabs$jajaja
ha\abss$hello what!
pbs
ubs
.abs
abs
pbt
ats
.b.
bs
bsaha
?abs
aaaaaaaaaaaaabs
+abs+
absssssss

View file

@ -0,0 +1,12 @@
Дефолт: Проверить что находит по паттерну:
{
"pattern": "some",
"text": "some text"
}
Проверка работы \>:
{
"pattern": "some\>",
"spaces": "abc"
"text": "sasobsomcsome"
}

38
2025.02.14/6Ex/Makefile Normal file
View file

@ -0,0 +1,38 @@
CFLAGS = -mfpmath=sse \
-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 \
-D_DEBUG -g \
-c
all: main.o array.o
gcc main.o array.o -lssp && del *.o
main.o: main.c
gcc $(CFLAGS) main.c
array.o: array.c
gcc $(CFLAGS) array.c

95
2025.02.14/6Ex/array.c Normal file
View file

@ -0,0 +1,95 @@
#include "array.h"
io_status process_s(const char* s, char* s1, char* s2, const size_t len_s)
{
size_t i;
int j;
for (i = 0, j = 0; i < len_s; ++i)
{
if (s[i] == '\\')
{
if (i + 1 == len_s) return ERROR_PATTERN;
else
{
s1[j] = '0';
s2[j++] = s[++i];
}
}
else if (s[i] == '.')
{
s1[j] = '1';
s2[j++] = '.';
}
else
{
s1[j] = '0';
s2[j++] = s[i];
}
}
s2[j] = '\0';
return SUCCESS;
}
io_status process_file(const char* f_in, const char* f_out, const char* s1, const char* s2, int* r)
{
FILE* fp = fopen(f_in, "r");
if (!fp) return ERROR_OPEN;
else
{
char buf[LEN] = {0};
size_t len_s = strlen(s2);
FILE* fw = fopen(f_out, "w");
int i;
if (!fw)
{
fclose(fp);
return ERROR_OPEN;
}
for (i = 0; fgets(buf, sizeof(buf), fp);)
{
size_t len_buf = strlen(buf);
bool is_approach;
if (buf[len_buf - 1] == '\n') buf[--len_buf] = '\0';
is_approach = process_string(buf, s1, s2, len_s, len_buf);
if (is_approach)
{
i++;
if (buf[len_buf - 1] == '\n') buf[len_buf - 1] = '\0';
fprintf(fw, "%s\n", buf);
}
}
*r = i;
fclose(fw);
}
fclose(fp);
return SUCCESS;
}
bool process_string(const char* buf, const char* s1, const char* s2, const size_t len_s,
const size_t len_buf)
{
if (len_buf < len_s) return false;
if (s1[0] == '1' || buf[0] == s2[0])
{
int j;
for (j = 1; j < (int)len_s; ++j)
{
if ((buf[j] != s2[j]) && (s1[j] == '0'))
{
break;
}
}
if (j == (int)len_s && j == (int)len_buf) return true;
}
return false;
}

13
2025.02.14/6Ex/array.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef ARRAY_H
#define ARRAY_H
#include "io_status.h"
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
io_status process_s(const char * s, char * s1, char * s2, const size_t len_s);
io_status process_file(const char* f_in, const char* f_out, const char* s1, const char* s2, int* r);
bool process_string(const char * buf, const char * s1, const char * s2, const size_t len_s, const size_t len_buf);
#endif

View file

@ -0,0 +1,13 @@
#ifndef IO_STATUS_H
#define IO_STATUS_H
#define LEN 1234
typedef enum io_status_ {
SUCCESS,
ERROR_OPEN,
ERROR_READ,
ERROR_PATTERN,
} io_status;
#endif

67
2025.02.14/6Ex/main.c Normal file
View file

@ -0,0 +1,67 @@
#include <stdio.h>
#include <time.h>
#include "io_status.h"
#include "array.h"
io_status task6(const char* f_in, const char* f_out, const char* s, int* res);
io_status task6(const char* f_in, const char* f_out, const char* s, int* res)
{
if (s == NULL) return ERROR_PATTERN;
else
{
size_t len_s = strlen(s);
io_status status;
char s1[len_s + 1]; // т.к. требуется место для \0
char s2[len_s + 1];
memset(s1, 0, len_s + 1);
memset(s2, 0, len_s + 1);
status = process_s(s, s1, s2, len_s);
if (status != SUCCESS) return status;
else
{
return process_file(f_in, f_out, s1, s2, res);
}
}
}
int main(int argc, char* argv[])
{
int task = 6;
io_status ret;
const char* f_in = 0;
const char* f_out = 0;
const char* s = 0;
int res = 0;
double t;
if (argc != 4)
{
printf("Usage: %s <f_in> <f_out> <s>\n", argv[0]);
return 1;
}
f_in = argv[1];
f_out = argv[2];
s = argv[3];
t = clock();
ret = task6(f_in, f_out, s, &res);
t = (clock() - t) / CLOCKS_PER_SEC;
switch (ret)
{
case SUCCESS:
printf("%s : Task = %d Result = %d Elapsed = %.2f\n",
argv[0], task, res, t);
break;
case ERROR_OPEN:
printf("Can not open %s\n", f_out);
return 1;
case ERROR_READ:
printf("Can not read %s\n", f_out);
return 2;
case ERROR_PATTERN:
printf("Error in pattern %s\n", s);
return 3;
}
return 0;
}

14
2025.02.14/6Ex/o.txt Normal file
View file

@ -0,0 +1,14 @@
abs
\abs
absababa
ahahabs
ahahahabsahhaha
^abs
ahahahabs$jajaja
ha\abss$hello what!
.abs
abs
?abs
aaaaaaaaaaaaabs
+abs+
absssssss

23
2025.02.14/6Ex/t.txt Normal file
View file

@ -0,0 +1,23 @@
abs
\abs
absababa
ahahabs
ahahahabsahhaha
^abs
ahahahabs$jajaja
ha\abss$hello what!
pbs
ubs
.abs
abs
pbt
ats
.b.
bs
bsaha
?abs
aaaaaaaaaaaaabs
+abs+
absssssss

View file

@ -0,0 +1,23 @@
Дефолт:
{
's': 'some'
'a': 'some\nhellosome\nsomeone'
}
\ в конце:
{
's': 'some\\\' - ERROR
'a': 'not important'
}
замена \some на some:
{
's': '\.wh\at'
'a': '.what'
}
Проверка шаблона:
{
's': 's.m.'
'a': 'some\nsone\nsumy\n.o.e\nsm'
}

13
2025.02.14/7Ex/Makefile Normal file
View file

@ -0,0 +1,13 @@
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
a07.exe: main.o solve.o
gcc main.o solve.o -o a07.exe -lssp
main.o: main.c
gcc $(CFLAGS) -c main.c
solve.o: solve.c
gcc $(FLAGS) -c solve.c
clean:
del *.o *.exe

View file

@ -0,0 +1,13 @@
#ifndef IO_STATUS_H
#define IO_STATUS_H
#define LEN 1234
typedef enum io_status_ {
SUCCESS,
ERROR_OPEN,
ERROR_READ,
ERROR_PATTERN,
} io_status;
#endif

67
2025.02.14/7Ex/main.c Normal file
View file

@ -0,0 +1,67 @@
#include <stdio.h>
#include <time.h>
#include "io_status.h"
#include "solve.h"
io_status task7(const char* f_in, const char* f_out, const char* s, int* res);
io_status task7(const char* f_in, const char* f_out, const char* s, int* res)
{
if (s == NULL) return ERROR_PATTERN;
else
{
size_t len_s = strlen(s);
io_status status;
char s1[len_s + 1]; // т.к. требуется место для \0
char s2[len_s + 1];
memset(s1, 0, len_s + 1);
memset(s2, 0, len_s + 1);
status = t7_process_s(s, s1, s2, len_s);
if (status != SUCCESS) return status;
else
{
return t7_process_file(f_in, f_out, s1, s2, res);
}
}
}
int main(int argc, char* argv[])
{
int task = 7;
io_status ret;
const char* f_in = 0;
const char* f_out = 0;
const char* s = 0;
int res = 0;
double t;
if (argc != 4)
{
printf("Usage: %s <f_in> <f_out> <s>\n", argv[0]);
return 1;
}
f_in = argv[1];
f_out = argv[2];
s = argv[3];
t = clock();
ret = task7(f_in, f_out, s, &res);
t = (clock() - t) / CLOCKS_PER_SEC;
switch (ret)
{
case SUCCESS:
printf("%s : Task = %d Result = %d Elapsed = %.2f\n",
argv[0], task, res, t);
break;
case ERROR_OPEN:
printf("Can not open %s\n", f_out);
return 1;
case ERROR_READ:
printf("Can not read %s\n", f_out);
return 2;
case ERROR_PATTERN:
printf("Error in pattern %s\n", s);
return 3;
}
return 0;
}

0
2025.02.14/7Ex/o.txt Normal file
View file

96
2025.02.14/7Ex/solve.c Normal file
View file

@ -0,0 +1,96 @@
#include "solve.h"
io_status t7_process_s(const char* s, char* s1, char* s2, const size_t len_s)
{
int i, j;
for (i = 0, j = 0; i < (int)len_s; ++i)
{
if (s[i] == '\\')
{
if (i + 1 == (int)len_s) return ERROR_PATTERN;
else
{
s1[j] = '0';
s2[j++] = s[++i];
}
}
else if ((s[i] == '?') && (j != 0))
{
s1[j - 1] = '1';
}
else
{
s1[j] = '0';
s2[j++] = s[i];
}
}
s2[j] = '\0';
return SUCCESS;
}
io_status t7_process_file(const char* f_in, const char* f_out, const char* s1, const char* s2, int* r)
{
FILE* fp = fopen(f_in, "r");
if (!fp) return ERROR_OPEN;
else
{
char buf[LEN] = {0};
size_t len_s = strlen(s2);
FILE* fw = fopen(f_out, "w");
int i;
if (!fw)
{
fclose(fp);
return ERROR_OPEN;
}
for (i = 0; fgets(buf, sizeof(buf), fp);)
{
size_t len_buf = strlen(buf);
bool is_approach;
if (len_buf > 0 && buf[len_buf - 1] == '\n') buf[--len_buf] = '\0';
is_approach = t7_start(buf, s1, s2, len_s, len_buf);
if (is_approach)
{
i++;
fprintf(fw, "%s\n", buf);
}
}
*r = i;
fclose(fw);
}
fclose(fp);
return SUCCESS;
}
bool t7_start(const char* buf, const char* s1, const char* s2, const size_t len_s, const size_t len_buf)
{
bool is_approach = false;
size_t char_s = sizeof(char);
if (len_s == 0)
{
if (len_buf == 0) return true;
return false;
}
if (s1[0] == '1')
{
is_approach = t7_start(buf, s1 + char_s, s2 + char_s, len_s - 1, len_buf);
if (is_approach) return true;
}
if (len_buf != 0 && buf[0] == s2[0])
{
is_approach = t7_start(buf + char_s, s1 + char_s, s2 + char_s, len_s - 1, len_buf - 1);
if (is_approach) return true;
}
return false;
}

13
2025.02.14/7Ex/solve.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef ARRAY_H
#define ARRAY_H
#include "io_status.h"
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
io_status t7_process_s(const char * s, char * s1, char * s2, const size_t len_s);
io_status t7_process_file(const char* f_in, const char* f_out, const char* s1, const char* s2, int* r);
bool t7_start(const char* buf, const char* s1, const char* s2, const size_t len_s, const size_t len_buf);
#endif

1
2025.02.14/7Ex/t.txt Normal file
View file

@ -0,0 +1 @@
a

View file

@ -0,0 +1,222 @@
{
"exe": "a07.exe",
"f_in": "input.txt",
"f_out": "output.txt",
"tests": [
{
"s": "some",
"text": "some\nnotsome\nrandom",
"expected": "some\n"
},
{
"s": "so?me",
"text": "some\nsme\nslome\nI'm sometimes",
"expected": "some\nsme\n"
},
{
"s": "s\\ome\\\\",
"text": "some\\",
"expected": "some\\\n"
},
{
"s": "some\\\\\\",
"text": "some\\",
"expected": "fall"
},
{
"s": "?oho",
"text": "?oho\noho",
"expected": "?oho\n"
},
{
"s": "a?",
"text": "\naha\na\na?\na????",
"expected": "\na\n"
},
{
"s": "abs",
"text": "abs\n\\abs\nabsababa\nahahabs\nahahahabsahhaha\n^abs\nahahahabs$jajaja\nha\\abss$hello what!\npbs\nubs\n.abs\nabs\npbt\natn.b.\nbs\nbsaha\n?abs\naaaaaaaaaaaaabs\n+abs+\nabsssssss\n\n",
"expected": "abs\nabs\n"
},
{
"s": "a??????",
"text": "a\naaa\n\n",
"expected": "a\n\n"
},
{
"s": "a\\????",
"text": "a\naaa\na?\na??",
"expected": "a\na?\n"
},
{
"s": "s\\ome\\\\",
"text": "some\\\nsome\ns\\ome\\\\\ns\\ome\\\nsome\\",
"expected": "some\\\nsome\\\n"
},
{
"s": "some\\\\\\",
"text": "some\\",
"expected": "fall"
},
{
"s": "ab????c",
"text": "abc\nac\nabbc\nab?c\nab???c\n",
"expected": "abc\nac\n"
},
{
"s": "\\?some",
"text": "?some\n\\?some\n?someother\n?som\n",
"expected": "?some\n"
},
{
"s": "",
"text": "hello\n\n\nabc",
"expected": "\n\n"
},
{
"s": "te\\?st",
"text": "te?st\nte\\?st\nte\\st\ntest",
"expected": "te?st\n"
},
{
"s": "hello?",
"text": "hello",
"expected": "hello\n"
},
{
"s": "hello?",
"text": "hell",
"expected": "hell\n"
},
{
"s": "hello?",
"text": "helloo",
"expected": ""
},
{
"s": "he?llo",
"text": "hllo",
"expected": "hllo\n"
},
{
"s": "he?llo",
"text": "hello",
"expected": "hello\n"
},
{
"s": "he?llo",
"text": "heeello",
"expected": ""
},
{
"s": "abc???",
"text": "abc",
"expected": "abc\n"
},
{
"s": "abc???",
"text": "ab",
"expected": "ab\n"
},
{
"s": "abc???",
"text": "abcd",
"expected": ""
},
{
"s": "?abc",
"text": "abc",
"expected": ""
},
{
"s": "?abc",
"text": "?abc",
"expected": "?abc\n"
},
{
"s": "abc\\?",
"text": "abc?",
"expected": "abc?\n"
},
{
"s": "abc\\?",
"text": "abc",
"expected": ""
},
{
"s": "ab??c",
"text": "ac",
"expected": "ac\n"
},
{
"s": "ab??c",
"text": "abc",
"expected": "abc\n"
},
{
"s": "ab??c",
"text": "abbc",
"expected": ""
},
{
"s": "a\\\\?",
"text": "a\\",
"expected": "a\\\n"
},
{
"s": "a\\\\?",
"text": "a",
"expected": "a\n"
},
{
"s": "\\?",
"text": "?",
"expected": "?\n"
},
{
"s": "\\?",
"text": "a",
"expected": ""
},
{
"s": "x??y??z",
"text": "xyz",
"expected": "xyz\n"
},
{
"s": "x??y??z",
"text": "xyyz",
"expected": ""
},
{
"s": "??abc",
"text": "abc",
"expected": "abc\n"
},
{
"s": "a?b?c?",
"text": "abc",
"expected": "abc\n"
},
{
"s": "a?b?c?",
"text": "ac",
"expected": "ac\n"
},
{
"s": "a?b?c?",
"text": "c",
"expected": "c\n"
},
{
"s": "a?b?c?",
"text": "ab",
"expected": "ab\n"
},
{
"s": "a?b?c?",
"text": "",
"expected": ""
}
]
}

View file

@ -0,0 +1,121 @@
import json
import subprocess
import os
import time
import platform
from colorama import Fore, Style, init
# Enable color support in Windows
init(autoreset=True)
def color_text(text, color):
"""Returns colored text"""
return color + text + Style.RESET_ALL
class TestCase:
"""Represents a single test case"""
def __init__(self, s, text, expected):
self.s = s
self.text = text
self.expected = expected
def should_fail(self):
"""Checks if the test expects a failure"""
return self.expected.lower() == "fall"
class TestSuite:
"""Handles loading and running test cases"""
def __init__(self, config_file):
self.config = self.load_config(config_file)
self.exe = self.config["exe"]
self.f_in = self.config["f_in"]
self.f_out = self.config["f_out"]
self.tests = [TestCase(**test) for test in self.config["tests"]]
@staticmethod
def load_config(filename):
"""Loads test cases from JSON"""
with open(filename, "r", encoding="utf-8") as f:
return json.load(f)
def run_command(cmd, exit_on_error=False):
"""Runs a shell command and handles errors"""
try:
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
return result
except subprocess.CalledProcessError as e:
print(color_text(f"[ERROR] Command failed: {cmd}", Fore.RED))
print(e.stderr)
if exit_on_error:
exit(1)
return None
def wait_for_executable(exe):
"""Waits for the executable file to appear after compilation"""
print(color_text(f"[WAIT] Waiting for {exe} to be compiled...", Fore.YELLOW))
while not os.path.exists(exe):
time.sleep(0.1) # Reduce CPU usage
print(color_text(f"[READY] {exe} compiled successfully.", Fore.GREEN))
def run_test(test_suite, test):
"""Runs the program and checks its result"""
exe, f_in, f_out = test_suite.exe, test_suite.f_in, test_suite.f_out
# Write input data to a file
with open(f_in, "w", encoding="utf-8") as f:
f.write(test.text)
# Windows fix: remove './' for executables
cmd = [exe, f_in, f_out, test.s] if platform.system() == "Windows" else [f"./{exe}", f_in, f_out, test.s]
# Run the program
result = run_command(cmd)
# Check if test expected failure
if test.should_fail():
if result and result.returncode != 0:
print(color_text(f"[PASS] Test '{test.s}' correctly failed (expected crash).", Fore.GREEN))
else:
print(color_text(f"[FAIL] Test '{test.s}' should have failed but did not.", Fore.RED))
return
# Read output file
try:
with open(f_out, "r", encoding="utf-8") as f:
output = f.read()
except FileNotFoundError:
output = None
# Check result
if output == test.expected:
print(color_text(f"[PASS] Test '{test.s}' passed.", Fore.GREEN))
else:
print(color_text(f"[FAIL] Test '{test.s}' failed.", Fore.RED))
print(f"Expected:\n{test.expected}")
print(f"Got:\n{output}")
# Cleanup test files
for file in [f_in, f_out]:
try:
os.remove(file)
except (FileNotFoundError, PermissionError):
print(color_text(f"[WARNING] Could not delete {file}, Windows may be locking it.", Fore.RED))
def main():
print(color_text("[CLEAN] Cleaning project...", Fore.BLUE))
run_command("make clean", exit_on_error=True)
print(color_text("[BUILD] Compiling project...", Fore.BLUE))
run_command("make", exit_on_error=True)
test_suite = TestSuite("test_cases.json")
wait_for_executable(test_suite.exe)
for test in test_suite.tests:
run_test(test_suite, test)
print(color_text("[CLEAN] Final cleanup...", Fore.BLUE))
run_command("make clean")
if __name__ == "__main__":
main()

View file

@ -0,0 +1,35 @@
Default:
{
s: 'some'
t: 'someone\nsome'
}
Проверка ?:
{
s: 's?ome'
t: 'some\nhome'
}
Проверка \s -> s:
{
s: 's\ome\\'
t: 'some\'
}
Проверка \:
{
s: 'some\\\'
t: 'not important'
}
Проверка \?:
{
s: '?oho'
t: 'haha?oho!'
}
Множество ?:
{
s: 'ha????ha'
t: 'hihihhahoho'
}

BIN
2025.02.14/8Ex/Linux.rar Normal file

Binary file not shown.

View file

@ -0,0 +1,38 @@
CFLAGS = -mfpmath=sse \
-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 \
-D_DEBUG -g \
-c
all: main.o array.o
gcc main.o array.o -o a08.out && rm *.o
main.o: main.c
gcc $(CFLAGS) main.c
array.o: array.c
gcc $(CFLAGS) array.c

View file

@ -0,0 +1,115 @@
#include "array.h"
io_status process_s(const char* s, char* s1, char* s2, const size_t len_s)
{
int i, j;
for (i = 0, j = 0; i < (int)len_s; ++i)
{
if (s[i] == '\\')
{
if (i + 1 == (int)len_s) return ERROR_PATTERN;
else
{
s1[j] = '0';
s2[j++] = s[++i];
}
}
else if ((s[i] == '+') && (j != 0))
{
s1[j - 1] = '1';
}
else
{
s1[j] = '0';
s2[j++] = s[i];
}
}
s2[j] = '\0';
return SUCCESS;
}
io_status process_file(const char* f_in, const char* f_out, const char* s1, const char* s2, int* r)
{
FILE* fp = fopen(f_in, "r");
if (!fp) return ERROR_OPEN;
else
{
char buf[LEN] = {0};
size_t len_s = strlen(s2);
FILE* fw = fopen(f_out, "w");
int i;
if (!fw)
{
fclose(fp);
return ERROR_OPEN;
}
for (i = 0; fgets(buf, sizeof(buf), fp);)
{
size_t len_buf = strlen(buf);
bool is_approach;
if (buf[len_buf - 1] == '\n') buf[--len_buf] = '\0';
is_approach = start(buf, s1, s2, len_s, len_buf);
if (is_approach)
{
i++;
if (buf[len_buf - 1] == '\n') buf[len_buf - 1] = '\0';
fprintf(fw, "%s\n", buf);
}
}
*r = i;
fclose(fw);
}
fclose(fp);
return SUCCESS;
}
bool start(const char* buf, const char* s1, const char* s2, const size_t len_s, const size_t len_buf)
{
size_t char_s = sizeof(char);
if (buf[0] == s2[0])
{
if (s1[0] == '1')
{
if (recursion(buf + char_s, s1, s2, len_s, len_buf - 1)) return true;
}
if (recursion(buf + char_s, s1 + char_s, s2 + char_s, len_s - 1, len_buf - 1)) return true;
}
return false;
}
bool recursion(const char* buf, const char* s1, const char* s2, const size_t len_s, const size_t len_buf)
{
size_t char_s = sizeof(char);
if (len_s == 0) return true;
else if (len_buf == 0) return false;
else
{
int i;
for (i = 0; i < (int)len_buf; ++i)
{
if (buf[i] == s2[i])
{
if (s1[i] == '1')
{
if (recursion(buf + (i + 1) * char_s, s1, s2, len_s, len_buf - 1)) return true;
}
if (i + 1 == (int)len_s) return true;
}
else
{
return false;
}
}
return false;
}
}

View file

@ -0,0 +1,14 @@
#ifndef ARRAY_H
#define ARRAY_H
#include "io_status.h"
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
io_status process_s(const char * s, char * s1, char * s2, const size_t len_s);
io_status process_file(const char* f_in, const char* f_out, const char* s1, const char* s2, int* r);
bool start(const char* buf, const char* s1, const char* s2, const size_t len_s, const size_t len_buf);
bool recursion(const char* buf, const char* s1, const char* s2, const size_t len_s, const size_t len_buf);
#endif

View file

@ -0,0 +1,13 @@
#ifndef IO_STATUS_H
#define IO_STATUS_H
#define LEN 1234
typedef enum io_status_ {
SUCCESS,
ERROR_OPEN,
ERROR_READ,
ERROR_PATTERN,
} io_status;
#endif

View file

@ -0,0 +1,67 @@
#include <stdio.h>
#include <time.h>
#include "io_status.h"
#include "array.h"
io_status task8(const char* f_in, const char* f_out, const char* s, int* res);
io_status task8(const char* f_in, const char* f_out, const char* s, int* res)
{
if (s == NULL) return ERROR_PATTERN;
else
{
size_t len_s = strlen(s);
io_status status;
char s1[len_s + 1]; // т.к. требуется место для \0
char s2[len_s + 1];
memset(s1, 0, len_s + 1);
memset(s2, 0, len_s + 1);
status = process_s(s, s1, s2, len_s);
if (status != SUCCESS) return status;
else
{
return process_file(f_in, f_out, s1, s2, res);
}
}
}
int main(int argc, char* argv[])
{
int task = 8;
io_status ret;
const char* f_in = 0;
const char* f_out = 0;
const char* s = 0;
int res = 0;
double t;
if (argc != 4)
{
printf("Usage: %s <f_in> <f_out> <s>\n", argv[0]);
return 1;
}
f_in = argv[1];
f_out = argv[2];
s = argv[3];
t = clock();
ret = task8(f_in, f_out, s, &res);
t = (clock() - t) / CLOCKS_PER_SEC;
switch (ret)
{
case SUCCESS:
printf("%s : Task = %d Result = %d Elapsed = %.2f\n",
argv[0], task, res, t);
break;
case ERROR_OPEN:
printf("Can not open %s\n", f_out);
return 1;
case ERROR_READ:
printf("Can not read %s\n", f_out);
return 2;
case ERROR_PATTERN:
printf("Error in pattern %s\n", s);
return 3;
}
return 0;
}

View file

@ -0,0 +1 @@
haaaaaaaaha

13
2025.02.14/8Ex/Makefile Normal file
View file

@ -0,0 +1,13 @@
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
a08.exe: main.o solve.o
gcc main.o solve.o -o a08.exe -lssp
main.o: main.c
gcc $(CFLAGS) -c main.c
solve.o: solve.c
gcc $(FLAGS) -c solve.c
clean:
del *.o *.exe

View file

@ -0,0 +1,13 @@
#ifndef IO_STATUS_H
#define IO_STATUS_H
#define LEN 1234
typedef enum io_status_ {
SUCCESS,
ERROR_OPEN,
ERROR_READ,
ERROR_PATTERN,
} io_status;
#endif

67
2025.02.14/8Ex/main.c Normal file
View file

@ -0,0 +1,67 @@
#include <stdio.h>
#include <time.h>
#include "io_status.h"
#include "solve.h"
io_status task8(const char* f_in, const char* f_out, const char* s, int* res);
io_status task8(const char* f_in, const char* f_out, const char* s, int* res)
{
if (s == NULL) return ERROR_PATTERN;
else
{
size_t len_s = strlen(s);
io_status status;
char s1[len_s + 1]; // т.к. требуется место для \0
char s2[len_s + 1];
memset(s1, 0, len_s + 1);
memset(s2, 0, len_s + 1);
status = t8_process_s(s, s1, s2, len_s);
if (status != SUCCESS) return status;
else
{
return t8_process_file(f_in, f_out, s1, s2, res);
}
}
}
int main(int argc, char* argv[])
{
int task = 8;
io_status ret;
const char* f_in = 0;
const char* f_out = 0;
const char* s = 0;
int res = 0;
double t;
if (argc != 4)
{
printf("Usage: %s <f_in> <f_out> <s>\n", argv[0]);
return 1;
}
f_in = argv[1];
f_out = argv[2];
s = argv[3];
t = clock();
ret = task8(f_in, f_out, s, &res);
t = (clock() - t) / CLOCKS_PER_SEC;
switch (ret)
{
case SUCCESS:
printf("%s : Task = %d Result = %d Elapsed = %.2f\n",
argv[0], task, res, t);
break;
case ERROR_OPEN:
printf("Can not open %s\n", f_out);
return 1;
case ERROR_READ:
printf("Can not read %s\n", f_out);
return 2;
case ERROR_PATTERN:
printf("Error in pattern %s\n", s);
return 3;
}
return 0;
}

84
2025.02.14/8Ex/solve.c Normal file
View file

@ -0,0 +1,84 @@
#include "solve.h"
io_status t8_process_s(const char* s, char* s1, char* s2, const size_t len_s)
{
int i, j;
for (i = 0, j = 0; i < (int)len_s; ++i)
{
if (s[i] == '\\')
{
if (i + 1 == (int)len_s) return ERROR_PATTERN;
else
{
s1[j] = '0';
s2[j++] = s[++i];
}
}
else if ((s[i] == '+') && (j != 0))
{
s1[j - 1] = '1';
}
else
{
s1[j] = '0';
s2[j++] = s[i];
}
}
s2[j] = '\0';
return SUCCESS;
}
io_status t8_process_file(const char* f_in, const char* f_out, const char* s1, const char* s2, int* r)
{
FILE* fp = fopen(f_in, "r");
if (!fp) return ERROR_OPEN;
else
{
char buf[LEN] = {0};
size_t len_s = strlen(s2);
FILE* fw = fopen(f_out, "w");
int i;
if (!fw)
{
fclose(fp);
return ERROR_OPEN;
}
for (i = 0; fgets(buf, sizeof(buf), fp);)
{
size_t len_buf = strlen(buf);
bool is_approach;
if (buf[len_buf - 1] == '\n') buf[--len_buf] = '\0';
is_approach = t8_recursion(buf, s1, s2, len_s, len_buf);
if (is_approach)
{
i++;
fprintf(fw, "%s\n", buf);
}
}
*r = i;
fclose(fw);
}
fclose(fp);
return SUCCESS;
}
bool t8_recursion(const char* buf, const char* s1, const char* s2, const size_t len_s, const size_t len_buf)
{
if (len_s == 0) return (len_buf == 0);
else if (len_buf == 0) return false;
if (buf[0] == s2[0])
{
if (s1[0] == '1') if (t8_recursion(buf + 1, s1, s2, len_s, len_buf - 1)) return true;
if (t8_recursion(buf + 1, s1 + 1, s2 + 1, len_s - 1, len_buf - 1)) return true;
}
return false;
}

13
2025.02.14/8Ex/solve.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef ARRAY_H
#define ARRAY_H
#include "io_status.h"
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
io_status t8_process_s(const char * s, char * s1, char * s2, const size_t len_s);
io_status t8_process_file(const char* f_in, const char* f_out, const char* s1, const char* s2, int* r);
bool t8_recursion(const char* buf, const char* s1, const char* s2, const size_t len_s, const size_t len_buf);
#endif

6
2025.02.14/8Ex/t.txt Normal file
View file

@ -0,0 +1,6 @@
aha
a
a+
a++
aaaaaaaa

View file

@ -0,0 +1,212 @@
{
"exe": "a08.exe",
"f_in": "input.txt",
"f_out": "output.txt",
"tests": [
{
"s": "some",
"text": "some\nnotsome\nrandom",
"expected": "some\n"
},
{
"s": "so+me",
"text": "some\nsooooome\nI'm sometimes",
"expected": "some\nsooooome\n"
},
{
"s": "s\\ome\\\\",
"text": "some\\",
"expected": "some\\\n"
},
{
"s": "some\\\\\\",
"text": "some\\",
"expected": "fall"
},
{
"s": "+oho",
"text": "+oho\noho",
"expected": "+oho\n"
},
{
"s": "a+",
"text": "\naha\na\na+\na++\naaaaaaaa\naa\naaaa\nbbb",
"expected": "a\naaaaaaaa\naa\naaaa\n"
},
{
"s": "abs",
"text": "abs\n\\abs\nabsababa\nahahabs\nahahahabsahhaha\n^abs\nahahahabs$jajaja\nha\\abss$hello what!\npbs\nubs\n.abs\nabs\npbt\natn.b.\nbs\nbsaha\n?abs\naaaaaaaaaaaaabs\n+abs+\nabsssssss\n\n",
"expected": "abs\nabs\n"
},
{
"s": "a+++++",
"text": "a\naaa\n\n",
"expected": "a\naaa\n"
},
{
"s": "a\\+++++",
"text": "a\naaa\na+\na++",
"expected": "a+\na++\n"
},
{
"s": "a+",
"text": "a\naa\naaa\naaaaaa\nb\naab\naaaaaax\n",
"expected": "a\naa\naaa\naaaaaa\n"
},
{
"s": "a+b",
"text": "ab\naab\naaaab\nacb",
"expected": "ab\naab\naaaab\n"
},
{
"s": "a++b",
"text": "ab\naab\naaaab",
"expected": "ab\naab\naaaab\n"
},
{
"s": "a+++b",
"text": "ab\naab\naaaab",
"expected": "ab\naab\naaaab\n"
},
{
"s": "+abc",
"text": "+abc\nabc\nxabc",
"expected": "+abc\n"
},
{
"s": "abc+",
"text": "abc\nabcc\nabcccc\nab",
"expected": "abc\nabcc\nabcccc\n"
},
{
"s": "a+b+c",
"text": "abc\naabbcc\naaaabbc",
"expected": "abc\naaaabbc\n"
},
{
"s": "a+b+c",
"text": "ac\nabbc",
"expected": "abbc\n"
},
{
"s": "a+b+c+",
"text": "abc\nabbcc\naaaabccccc",
"expected": "abc\nabbcc\naaaabccccc\n"
},
{
"s": "a+b+c+",
"text": "ac\nabb\n",
"expected": ""
},
{
"s": "a+b+c+d+",
"text": "abcd\naabbdcddd\naaaabbccddddd",
"expected": "abcd\naaaabbccddddd\n"
},
{
"s": "hello+world",
"text": "helloworld\nhelloooooworld\nhelo+world",
"expected": "helloworld\nhelloooooworld\n"
},
{
"s": "a\\+b",
"text": "a+b\nab\naab",
"expected": "a+b\n"
},
{
"s": "a++",
"text": "a\naa\naaa\naaaa",
"expected": "a\naa\naaa\naaaa\n"
},
{
"s": "a+++b+",
"text": "ab\naab\naaaabb\nabb",
"expected": "ab\naab\naaaabb\nabb\n"
},
{
"s": "x+y+z+",
"text": "xyz\nxxyz\nxxxxyzzzz",
"expected": "xyz\nxxyz\nxxxxyzzzz\n"
},
{
"s": "x+y+z+",
"text": "xz\nxyz\nxyzz",
"expected": "xyz\nxyzz\n"
},
{
"s": "+abc",
"text": "+abc\nabc\nxabc",
"expected": "+abc\n"
},
{
"s": "abc+",
"text": "abc\nabcc\nabccc\nab\n",
"expected": "abc\nabcc\nabccc\n"
},
{
"s": "so+me",
"text": "some\nsooooome\nsometimes\n",
"expected": "some\nsooooome\n"
},
{
"s": "a+b",
"text": "ab\naab\naaaab\nacb\n",
"expected": "ab\naab\naaaab\n"
},
{
"s": "a++b",
"text": "ab\naab\naaaab\nazb\n",
"expected": "ab\naab\naaaab\n"
},
{
"s": "a+++++b",
"text": "ab\naab\naaaab\naaaaaab\naxb\n",
"expected": "ab\naab\naaaab\naaaaaab\n"
},
{
"s": "start+end",
"text": "startend\nstartttend\nstart\nstartende\n",
"expected": "startend\nstartttend\n"
},
{
"s": "m++n",
"text": "mn\nmmn\nmmmn\nn\nmnn\n",
"expected": "mn\nmmn\nmmmn\n"
},
{
"s": "z+z",
"text": "z\nzz\nzzz\nzzzz\nzzzza\n",
"expected": "zz\nzzz\nzzzz\n"
},
{
"s": "++abc",
"text": "++abc\n+abc\n+++abc\n++++abc\n++abcd\n",
"expected": "++abc\n+abc\n+++abc\n++++abc\n"
},
{
"s": "slash\\+slash",
"text": "slash+slash\nslashslash\nslash++slash\n",
"expected": "slash+slash\n"
},
{
"s": "abc\\+def",
"text": "abc+def\nabc++def\nabcdef\nabc+defg\n",
"expected": "abc+def\n"
},
{
"s": "my++test",
"text": "mytest\nmyytest\nmtest\nmytests\n",
"expected": "mytest\nmyytest\n"
},
{
"s": "end+",
"text": "end\nendd\nenddd\nen\nendxd\n",
"expected": "end\nendd\nenddd\n"
},
{
"s": "",
"text": "some\nboy\nwhant\nto\nsee\n\n",
"expected": "\n"
}
]
}

View file

@ -0,0 +1,121 @@
import json
import subprocess
import os
import time
import platform
from colorama import Fore, Style, init
# Enable color support in Windows
init(autoreset=True)
def color_text(text, color):
"""Returns colored text"""
return color + text + Style.RESET_ALL
class TestCase:
"""Represents a single test case"""
def __init__(self, s, text, expected):
self.s = s
self.text = text
self.expected = expected
def should_fail(self):
"""Checks if the test expects a failure"""
return self.expected.lower() == "fall"
class TestSuite:
"""Handles loading and running test cases"""
def __init__(self, config_file):
self.config = self.load_config(config_file)
self.exe = self.config["exe"]
self.f_in = self.config["f_in"]
self.f_out = self.config["f_out"]
self.tests = [TestCase(**test) for test in self.config["tests"]]
@staticmethod
def load_config(filename):
"""Loads test cases from JSON"""
with open(filename, "r", encoding="utf-8") as f:
return json.load(f)
def run_command(cmd, exit_on_error=False):
"""Runs a shell command and handles errors"""
try:
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
return result
except subprocess.CalledProcessError as e:
print(color_text(f"[ERROR] Command failed: {cmd}", Fore.RED))
print(e.stderr)
if exit_on_error:
exit(1)
return None
def wait_for_executable(exe):
"""Waits for the executable file to appear after compilation"""
print(color_text(f"[WAIT] Waiting for {exe} to be compiled...", Fore.YELLOW))
while not os.path.exists(exe):
time.sleep(0.1) # Reduce CPU usage
print(color_text(f"[READY] {exe} compiled successfully.", Fore.GREEN))
def run_test(test_suite, test):
"""Runs the program and checks its result"""
exe, f_in, f_out = test_suite.exe, test_suite.f_in, test_suite.f_out
# Write input data to a file
with open(f_in, "w", encoding="utf-8") as f:
f.write(test.text)
# Windows fix: remove './' for executables
cmd = [exe, f_in, f_out, test.s] if platform.system() == "Windows" else [f"./{exe}", f_in, f_out, test.s]
# Run the program
result = run_command(cmd)
# Check if test expected failure
if test.should_fail():
if result and result.returncode != 0:
print(color_text(f"[PASS] Test '{test.s}' correctly failed (expected crash).", Fore.GREEN))
else:
print(color_text(f"[FAIL] Test '{test.s}' should have failed but did not.", Fore.RED))
return
# Read output file
try:
with open(f_out, "r", encoding="utf-8") as f:
output = f.read()
except FileNotFoundError:
output = None
# Check result
if output == test.expected:
print(color_text(f"[PASS] Test '{test.s}' passed.", Fore.GREEN))
else:
print(color_text(f"[FAIL] Test '{test.s}' failed.", Fore.RED))
print(f"Expected:\n{test.expected}")
print(f"Got:\n{output}")
# Cleanup test files
for file in [f_in, f_out]:
try:
os.remove(file)
except (FileNotFoundError, PermissionError):
print(color_text(f"[WARNING] Could not delete {file}, Windows may be locking it.", Fore.RED))
def main():
print(color_text("[CLEAN] Cleaning project...", Fore.BLUE))
run_command("make clean", exit_on_error=True)
print(color_text("[BUILD] Compiling project...", Fore.BLUE))
run_command("make", exit_on_error=True)
test_suite = TestSuite("test_cases.json")
wait_for_executable(test_suite.exe)
for test in test_suite.tests:
run_test(test_suite, test)
print(color_text("[CLEAN] Final cleanup...", Fore.BLUE))
run_command("make clean")
if __name__ == "__main__":
main()

View file

@ -0,0 +1,76 @@
Default:
{
s: 'some'
t: 'some'
}
Проверка, что если часть предложения:
{
s: 'some'
t: 'somebody here!?'
}
Проверка +:
{
s: 'so+me'
t: 'sooooome\nsme\nsome'
}
Проверка \s -> s:
{
s: 's\ome\\'
t: 'some\'
}
Проверка \:
{
s: 'some\\\'
t: 'not important'
}
Проверка \+:
{
s: '+o\+o'
t: '+o+o'
}
Множество +:
{
s: 'ha++++++ha'
t: 'haaaaaaaaha'
}
Проверка на не выход за стэк:
{
s: 'som+e'
t: 'sommmme'
}
abs
\abs
absababa
ahahabs
ahahahabsahhaha
^abs
ahahahabs$jajaja
ha\abss$hello what!
pbs
ubs
.abs
abs
pbt
ats
.b.
bs
bsaha
?abs
aaaaaaaaaaaaabs
+abs+
absssssss
abs*
somePalongPway
some
howPsomePitPbe
howPsomething
whyPanysome

38
2025.02.14/9Ex/Makefile Normal file
View file

@ -0,0 +1,38 @@
CFLAGS = -mfpmath=sse \
-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 \
-D_DEBUG -g \
-c
all: main.o array.o
gcc main.o array.o -lssp && del *.o
main.o: main.c
gcc $(CFLAGS) main.c
array.o: array.c
gcc $(CFLAGS) array.c

133
2025.02.14/9Ex/array.c Normal file
View file

@ -0,0 +1,133 @@
#include "array.h"
io_status process_s(const char* s, char* s1, char* s2, const size_t len_s)
{
int i, j;
for (i = 0, j = 0; i < (int)len_s; ++i)
{
if (s[i] == '\\')
{
if (i + 1 == (int)len_s) return ERROR_PATTERN;
else
{
s1[j] = '0';
s2[j++] = s[++i];
}
}
else if ((s[i] == '*') && (j != 0))
{
s1[j - 1] = '1';
}
else
{
s1[j] = '0';
s2[j++] = s[i];
}
}
s2[j] = '\0';
return SUCCESS;
}
io_status process_file(const char* f_in, const char* f_out, const char* s1, const char* s2, int* r)
{
FILE* fp = fopen(f_in, "r");
if (!fp) return ERROR_OPEN;
else
{
char buf[LEN] = {0};
size_t len_s = strlen(s2);
FILE* fw = fopen(f_out, "w");
int i;
if (!fw)
{
fclose(fp);
return ERROR_OPEN;
}
for (i = 0; fgets(buf, sizeof(buf), fp);)
{
size_t len_buf = strlen(buf);
bool is_approach;
if (len_buf > 0 && buf[len_buf - 1] == '\n') buf[--len_buf] = '\0';
is_approach = start(buf, s1, s2, len_s, len_buf);
if (is_approach)
{
i++;
if (buf[len_buf - 1] == '\n') buf[len_buf - 1] = '\0';
fprintf(fw, "%s\n", buf);
}
}
*r = i;
fclose(fw);
}
fclose(fp);
return SUCCESS;
}
bool start(const char* buf, const char* s1, const char* s2, const size_t len_s, const size_t len_buf)
{
size_t char_s = sizeof(char);
if (buf[0] == s2[0])
{
if (s1[0] == '1')
{
if (recursion(buf + char_s, s1, s2, len_s, len_buf - 1)) return true;
else if (recursion(buf, s1 + char_s, s2 + char_s, len_s - 1, len_buf)) return true;
}
if (len_buf == 0 && len_s == 0) return true;
return recursion(buf + char_s, s1 + char_s, s2 + char_s, len_s - 1, len_buf - 1);
}
if (s1[0] == '1') return recursion(buf, s1 + char_s, s2 + char_s, len_s - 1, len_buf);
return false;
}
bool recursion(const char* buf, const char* s1, const char* s2, const size_t len_s, const size_t len_buf)
{
size_t char_s = sizeof(char);
if (len_s == 0)
{
if (len_buf == 0) return true;
return false;
}
else if (len_buf == 0) return false;
else
{
int i;
for (i = 0; i < (int)len_buf; ++i)
{
if (buf[i] == s2[i])
{
if (s1[i] == '1')
{
if (recursion(buf + (i + 1) * char_s, s1 + i * char_s, s2 + i * char_s, len_s - i,
len_buf - (i + 1)))
return true;
else if (recursion(buf + i * char_s, s1 + (i + 1) * char_s, s2 + (i + 1) * char_s, len_s - (i + 1),
len_buf - i))
return true;
}
}
else
{
if (s1[i] == '1')
{
return (recursion(buf + i * char_s, s1 + (i + 1) * char_s, s2 + (i + 1) * char_s, len_s - (i + 1),
len_buf - i));
return true;
}
return false;
}
}
if (i == (int)len_s) return true;
return false;
}
}

14
2025.02.14/9Ex/array.h Normal file
View file

@ -0,0 +1,14 @@
#ifndef ARRAY_H
#define ARRAY_H
#include "io_status.h"
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
io_status process_s(const char * s, char * s1, char * s2, const size_t len_s);
io_status process_file(const char* f_in, const char* f_out, const char* s1, const char* s2, int* r);
bool start(const char* buf, const char* s1, const char* s2, const size_t len_s, const size_t len_buf);
bool recursion(const char* buf, const char* s1, const char* s2, const size_t len_s, const size_t len_buf);
#endif

View file

@ -0,0 +1,13 @@
#ifndef IO_STATUS_H
#define IO_STATUS_H
#define LEN 1234
typedef enum io_status_ {
SUCCESS,
ERROR_OPEN,
ERROR_READ,
ERROR_PATTERN,
} io_status;
#endif

67
2025.02.14/9Ex/main.c Normal file
View file

@ -0,0 +1,67 @@
#include <stdio.h>
#include <time.h>
#include "io_status.h"
#include "array.h"
io_status task9(const char* f_in, const char* f_out, const char* s, int* res);
io_status task9(const char* f_in, const char* f_out, const char* s, int* res)
{
if (s == NULL) return ERROR_PATTERN;
else
{
size_t len_s = strlen(s);
io_status status;
char s1[len_s + 1]; // т.к. требуется место для \0
char s2[len_s + 1];
memset(s1, 0, len_s + 1);
memset(s2, 0, len_s + 1);
status = process_s(s, s1, s2, len_s);
if (status != SUCCESS) return status;
else
{
return process_file(f_in, f_out, s1, s2, res);
}
}
}
int main(int argc, char* argv[])
{
int task = 9;
io_status ret;
const char* f_in = 0;
const char* f_out = 0;
const char* s = 0;
int res = 0;
double t;
if (argc != 4)
{
printf("Usage: %s <f_in> <f_out> <s>\n", argv[0]);
return 1;
}
f_in = argv[1];
f_out = argv[2];
s = argv[3];
t = clock();
ret = task9(f_in, f_out, s, &res);
t = (clock() - t) / CLOCKS_PER_SEC;
switch (ret)
{
case SUCCESS:
printf("%s : Task = %d Result = %d Elapsed = %.2f\n",
argv[0], task, res, t);
break;
case ERROR_OPEN:
printf("Can not open %s\n", f_out);
return 1;
case ERROR_READ:
printf("Can not read %s\n", f_out);
return 2;
case ERROR_PATTERN:
printf("Error in pattern %s\n", s);
return 3;
}
return 0;
}

2
2025.02.14/9Ex/o.txt Normal file
View file

@ -0,0 +1,2 @@
abs
abs

23
2025.02.14/9Ex/t.txt Normal file
View file

@ -0,0 +1,23 @@
abs
\abs
absababa
ahahabs
ahahahabsahhaha
^abs
ahahahabs$jajaja
ha\abss$hello what!
pbs
ubs
.abs
abs
pbt
ats
.b.
bs
bsaha
?abs
aaaaaaaaaaaaabs
+abs+
absssssss

View file

@ -0,0 +1,47 @@
Default:
{
s: 'some'
t: 'some\nheysome\nsomeone\nhey someone!'
}
Проверка, на отсутствие буквы:
{
s: 'so*me'
t: 'sme\nsome\nsume'
}
Проверка, на множественное повторение:
{
s: 'so*me'
t: 'sooooome\nsme\nsome\nsiiiime'
}
Проверка \s -> s:
{
s: 's\ome\\'
t: 'some\'
}
Проверка, что если заканчивается t, то он не подходит
{
s: 'something'
t: 'some'
}
Проверка \:
{
s: 'some\\\'
t: 'not important'
}
Проверка \*:
{
s: '*o\*o'
t: '*o*o\no*o\n**o*o\n*ooooo\n**o\n*oooo*o'
}
Множество *:
{
s: 'ha*****ha'
t: 'haaaaaaaaha'
}

Binary file not shown.

View file

@ -0,0 +1,13 @@
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
gcc $(FLAGS) $^ -o $@
%.o: %.c
gcc -c $(FLAGS) $<
all: a01.out a02.out a03.out a04.out a06.out a07.out a08.out a09.out
solve.o: solve.c solve.h
clean:
rm -f *.o *.out

View file

@ -0,0 +1,59 @@
#include <stdio.h>
#include <time.h>
#include <string.h>
#include "io_status.h"
#include "solve.h"
io_status task1(const char* f_in, const char* f_out, const char* s, int* res);
io_status task1(const char* f_in, const char* f_out, const char* s, int* res)
{
if (s == NULL) return ERROR_PATTERN;
else
{
size_t len_s = strlen(s);
io_status status;
char s1[len_s + 1], s2[len_s + 1];
memset(s1, 0, len_s + 1);
memset(s2, 0, len_s + 1);
status = t1_process_s(s, s1, s2, len_s);
if (status != SUCCESS) return status;
return t1_process_file(f_in, f_out, s1, s2, res);
}
}
int main(int argc, char* argv[])
{
int task = 1;
io_status ret;
const char *f_in, *f_out, *s;
int res = 0;
double t;
if (argc != 4)
{
printf("Usage: %s <f_in> <f_out> <s>\n", argv[0]);
return 1;
}
f_in = argv[1];
f_out = argv[2];
s = argv[3];
t = clock();
ret = task1(f_in, f_out, s, &res);
t = (clock() - t) / CLOCKS_PER_SEC;
switch (ret)
{
case SUCCESS:
printf("%s : Task = %d Result = %d Elapsed = %.2f\n", argv[0], task, res, t);
break;
case ERROR_OPEN:
printf("Can not open %s\n", f_out);
return 1;
case ERROR_READ:
printf("Can not read %s\n", f_out);
return 2;
case ERROR_PATTERN:
printf("Error in pattern %s\n", s);
return 3;
}
return 0;
}

View file

@ -0,0 +1,59 @@
#include <stdio.h>
#include <time.h>
#include <string.h>
#include "io_status.h"
#include "solve.h"
io_status task2(const char* f_in, const char* f_out, const char* s, int* res);
io_status task2(const char* f_in, const char* f_out, const char* s, int* res)
{
if (s == NULL) return ERROR_PATTERN;
else
{
size_t len_s = strlen(s);
io_status status;
char s1[len_s + 1], s2[len_s + 1];
memset(s1, 0, len_s + 1);
memset(s2, 0, len_s + 1);
status = t2_process_s(s, s1, s2, len_s);
if (status != SUCCESS) return status;
return t2_process_file(f_in, f_out, s1, s2, res);
}
}
int main(int argc, char* argv[])
{
int task = 2;
io_status ret;
const char *f_in, *f_out, *s;
int res = 0;
double t;
if (argc != 4)
{
printf("Usage: %s <f_in> <f_out> <s>\n", argv[0]);
return 1;
}
f_in = argv[1];
f_out = argv[2];
s = argv[3];
t = clock();
ret = task2(f_in, f_out, s, &res);
t = (clock() - t) / CLOCKS_PER_SEC;
switch (ret)
{
case SUCCESS:
printf("%s : Task = %d Result = %d Elapsed = %.2f\n", argv[0], task, res, t);
break;
case ERROR_OPEN:
printf("Can not open %s\n", f_out);
return 1;
case ERROR_READ:
printf("Can not read %s\n", f_out);
return 2;
case ERROR_PATTERN:
printf("Error in pattern %s\n", s);
return 3;
}
return 0;
}

View file

@ -0,0 +1,56 @@
#include <stdio.h>
#include <time.h>
#include <string.h>
#include "io_status.h"
#include "solve.h"
io_status task3(const char* f_in, const char* f_out, const char* s, const char* t_param, int* res);
io_status task3(const char* f_in, const char* f_out, const char* s, const char* t_param, int* res) {
if (s == NULL) return ERROR_PATTERN;
else
{
size_t len_s = strlen(s);
io_status status;
char s1[len_s + 1], s2[len_s + 1];
memset(s1, 0, len_s + 1);
memset(s2, 0, len_s + 1);
status = t3_process_s(s, s1, s2, len_s);
if (status != SUCCESS) return status;
return t3_process_file(f_in, f_out, s1, s2, t_param, res);
}
}
int main(int argc, char* argv[]) {
int task = 3;
io_status ret;
const char *f_in, *f_out, *s, *t_param;
int res = 0;
double t;
if (argc != 5) {
printf("Usage: %s <f_in> <f_out> <s> <t>\n", argv[0]);
return 1;
}
f_in = argv[1];
f_out = argv[2];
s = argv[3];
t_param = argv[4];
t = clock();
ret = task3(f_in, f_out, s, t_param, &res);
t = (clock() - t) / CLOCKS_PER_SEC;
switch (ret) {
case SUCCESS:
printf("%s : Task = %d Result = %d Elapsed = %.2f\n", argv[0], task, res, t);
break;
case ERROR_OPEN:
printf("Can not open %s\n", f_out);
return 1;
case ERROR_READ:
printf("Can not read %s\n", f_out);
return 2;
case ERROR_PATTERN:
printf("Error in pattern %s\n", s);
return 3;
}
return 0;
}

View file

@ -0,0 +1,60 @@
#include <stdio.h>
#include <time.h>
#include <string.h>
#include "io_status.h"
#include "solve.h"
io_status task4(const char* f_in, const char* f_out, const char* s, const char* t_param, int* res);
io_status task4(const char* f_in, const char* f_out, const char* s, const char* t_param, int* res)
{
if (s == NULL) return ERROR_PATTERN;
else
{
size_t len_s = strlen(s);
io_status status;
char s1[len_s + 1], s2[len_s + 1];
memset(s1, 0, len_s + 1);
memset(s2, 0, len_s + 1);
status = t4_process_s(s, s1, s2, len_s);
if (status != SUCCESS) return status;
return t4_process_file(f_in, f_out, s1, s2, t_param, res);
}
}
int main(int argc, char* argv[])
{
int task = 4;
io_status ret;
const char *f_in, *f_out, *s, *t_param;
int res = 0;
double t;
if (argc != 5)
{
printf("Usage: %s <f_in> <f_out> <s> <t>\n", argv[0]);
return 1;
}
f_in = argv[1];
f_out = argv[2];
s = argv[3];
t_param = argv[4];
t = clock();
ret = task4(f_in, f_out, s, t_param, &res);
t = (clock() - t) / CLOCKS_PER_SEC;
switch (ret)
{
case SUCCESS:
printf("%s : Task = %d Result = %d Elapsed = %.2f\n", argv[0], task, res, t);
break;
case ERROR_OPEN:
printf("Can not open %s\n", f_out);
return 1;
case ERROR_READ:
printf("Can not read %s\n", f_out);
return 2;
case ERROR_PATTERN:
printf("Error in pattern %s\n", s);
return 3;
}
return 0;
}

View file

@ -0,0 +1,55 @@
#include <stdio.h>
#include <time.h>
#include <string.h>
#include "io_status.h"
#include "solve.h"
io_status task6(const char* f_in, const char* f_out, const char* s, int* res);
io_status task6(const char* f_in, const char* f_out, const char* s, int* res) {
if (s == NULL) return ERROR_PATTERN;
else
{
size_t len_s = strlen(s);
io_status status;
char s1[len_s + 1], s2[len_s + 1];
memset(s1, 0, len_s + 1);
memset(s2, 0, len_s + 1);
status = t6_process_s(s, s1, s2, len_s);
if (status != SUCCESS) return status;
return t6_process_file(f_in, f_out, s1, s2, res);
}
}
int main(int argc, char* argv[]) {
int task = 6;
io_status ret;
const char *f_in, *f_out, *s;
int res = 0;
double t;
if (argc != 4) {
printf("Usage: %s <f_in> <f_out> <s>\n", argv[0]);
return 1;
}
f_in = argv[1];
f_out = argv[2];
s = argv[3];
t = clock();
ret = task6(f_in, f_out, s, &res);
t = (clock() - t) / CLOCKS_PER_SEC;
switch (ret) {
case SUCCESS:
printf("%s : Task = %d Result = %d Elapsed = %.2f\n", argv[0], task, res, t);
break;
case ERROR_OPEN:
printf("Can not open %s\n", f_out);
return 1;
case ERROR_READ:
printf("Can not read %s\n", f_out);
return 2;
case ERROR_PATTERN:
printf("Error in pattern %s\n", s);
return 3;
}
return 0;
}

View file

@ -0,0 +1,55 @@
#include <stdio.h>
#include <time.h>
#include <string.h>
#include "io_status.h"
#include "solve.h"
io_status task7(const char* f_in, const char* f_out, const char* s, int* res);
io_status task7(const char* f_in, const char* f_out, const char* s, int* res) {
if (s == NULL) return ERROR_PATTERN;
else
{
size_t len_s = strlen(s);
io_status status;
char s1[len_s + 1], s2[len_s + 1];
memset(s1, 0, len_s + 1);
memset(s2, 0, len_s + 1);
status = t7_process_s(s, s1, s2, len_s);
if (status != SUCCESS) return status;
return t7_process_file(f_in, f_out, s1, s2, res);
}
}
int main(int argc, char* argv[]) {
int task = 7;
io_status ret;
const char *f_in, *f_out, *s;
int res = 0;
double t;
if (argc != 4) {
printf("Usage: %s <f_in> <f_out> <s>\n", argv[0]);
return 1;
}
f_in = argv[1];
f_out = argv[2];
s = argv[3];
t = clock();
ret = task7(f_in, f_out, s, &res);
t = (clock() - t) / CLOCKS_PER_SEC;
switch (ret) {
case SUCCESS:
printf("%s : Task = %d Result = %d Elapsed = %.2f\n", argv[0], task, res, t);
break;
case ERROR_OPEN:
printf("Can not open %s\n", f_out);
return 1;
case ERROR_READ:
printf("Can not read %s\n", f_out);
return 2;
case ERROR_PATTERN:
printf("Error in pattern %s\n", s);
return 3;
}
return 0;
}

Some files were not shown because too many files have changed in this diff Show more