refactor(structure): normalize folder names with leading zeros for consistency
- Renamed all folders from format NEx (e.g., 1Ex, 2Ex...) to 0NEx (01Ex, 02Ex, etc.) - Updated subdirectories and files accordingly - Removed old main Makefile and tasks (a01.c–a09.c, solve.c, io_status.h), likely obsolete - Cleaned up deprecated task binaries and configs
This commit is contained in:
parent
2cf18a1ff3
commit
8a7aac7c23
385 changed files with 2 additions and 1468 deletions
38
2025.02.14/04Ex/Makefile
Normal file
38
2025.02.14/04Ex/Makefile
Normal 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/04Ex/array.c
Normal file
135
2025.02.14/04Ex/array.c
Normal 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/04Ex/array.h
Normal file
14
2025.02.14/04Ex/array.h
Normal 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
|
13
2025.02.14/04Ex/io_status.h
Normal file
13
2025.02.14/04Ex/io_status.h
Normal 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/04Ex/main.c
Normal file
69
2025.02.14/04Ex/main.c
Normal 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/04Ex/o.txt
Normal file
0
2025.02.14/04Ex/o.txt
Normal file
23
2025.02.14/04Ex/t.txt
Normal file
23
2025.02.14/04Ex/t.txt
Normal 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
|
||||
|
||||
|
12
2025.02.14/04Ex/Примеры
Normal file
12
2025.02.14/04Ex/Примеры
Normal file
|
@ -0,0 +1,12 @@
|
|||
Дефолт: Проверить что находит по паттерну:
|
||||
{
|
||||
"pattern": "some",
|
||||
"text": "some text"
|
||||
}
|
||||
|
||||
Проверка работы \>:
|
||||
{
|
||||
"pattern": "some\>",
|
||||
"spaces": "abc"
|
||||
"text": "sasobsomcsome"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue