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:
AZEN-SGG 2025-03-23 21:14:20 +03:00
parent 2cf18a1ff3
commit 8a7aac7c23
385 changed files with 2 additions and 1468 deletions

19
2025.02.28/01Ex/Makefile Normal file
View file

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

5
2025.02.28/01Ex/a.txt Normal file
View file

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

61
2025.02.28/01Ex/array.c Normal file
View file

@ -0,0 +1,61 @@
#include "array.h"
io_status read_array(char* a[], int n, const char * name)
{
char buf[LEN] = {0};
FILE *fp = 0;
int i, j;
if (!(fp = fopen(name, "r"))) return ERROR_OPEN;
for (i = 0; i < n; i++) {
if (!fgets(buf, sizeof(buf), fp))
{
fclose(fp);
free_array(a, i);
return ERROR_READ;
}
for (j = 0; buf[j]; j++)
{
if (buf[j] == '\n')
{
buf[j] = 0;
break;
}
}
a[i] = (char *)malloc((j+1) * sizeof(char));
if (!a[i])
{
fclose(fp);
free_array(a, i);
return ERROR_MEM;
}
strcpy(a[i], buf);
}
fclose(fp);
return SUCCESS;
}
void free_array(char ** a, int n)
{
int i;
for(i = 0; i < n; ++i)
{
if (a[i])
{
free(a[i]);
a[i] = 0;
}
}
}
void print_array(char ** a, int n, int m)
{
int l = (n > m ? m : n);
int i;
for (i = 0; i < l; ++i) printf("%s\n", a[i]);
}

14
2025.02.28/01Ex/array.h Normal file
View file

@ -0,0 +1,14 @@
#ifndef ARRAY_H
#define ARRAY_H
#include "io_status.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
io_status read_array(char *a[], int n, const char *name);
void free_array(char **a, int n);
void print_array(char **a, int n, int m);
#endif

View file

@ -0,0 +1,14 @@
#ifndef IO_STATUS_H
#define IO_STATUS_H
#define LEN 1234
typedef enum _io_status
{
SUCCESS,
ERROR_OPEN,
ERROR_READ,
ERROR_MEM
} io_status;
#endif

66
2025.02.28/01Ex/main.c Normal file
View file

@ -0,0 +1,66 @@
#include "solve.h"
#include "sort.h"
#include "array.h"
#include "io_status.h"
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main(int argc, char *argv[])
{
/* ./aout x c n p filename */
int c, p, n, res, task = 1;
io_status ret;
char *name, *x, **a;
int (*cmp)(const char *, const char *);
int (*f[])(const char *, const char *) = {up_strcmp, down_strcmp, up_len, down_len};
int len_f = sizeof(f) / sizeof(f[0]);
double t;
if (!(argc == 6 && sscanf(argv[2], "%d", &c) && sscanf(argv[3], "%d", &n) == 1 && sscanf(argv[4], "%d", &p) == 1 && c >= 1 && c <= len_f))
{
printf("Usage %s x c n p name\n", argv[0]);
return 1;
}
x = argv[1];
name = argv[5];
cmp = f[c-1];
if (!(a = (char **)malloc(n * sizeof(char *))))
{
printf("Not enough memory: \n");
return 2;
}
ret = read_array(a, n, name);
do {
switch(ret)
{
case SUCCESS:
continue;
case ERROR_OPEN:
printf("Cannot open %s\n", name);
break;
case ERROR_READ:
printf("Cannot read %s\n", name);
break;
case ERROR_MEM:
printf("Not enough memory");
break;
}
free(a);
return 3;
} while (0);
print_array(a, n, p);
t = clock();
res = t1_solve(a, n, x, cmp);
t = (clock() - t) / CLOCKS_PER_SEC;
printf("%s : Task = %d Res = %d Elapsed = %.2f\n", argv[0], task, res, t);
free_array(a, n);
free(a);
return 0;
}

14
2025.02.28/01Ex/solve.c Normal file
View file

@ -0,0 +1,14 @@
#include "solve.h"
int t1_solve(char **a, int n, char *x, int (*cmp)(const char *, const char *)) {
int avg = (n + (-1)*(n%2)) / 2;
int comp;
if (n == 0) return 0;
comp = cmp(x, a[avg]);
if (comp < 0) return t1_solve(a, avg, x, cmp);
if (comp > 0) return avg+1 + t1_solve(a+avg+1, n-(avg+1), x, cmp);
else return avg;
}

8
2025.02.28/01Ex/solve.h Normal file
View file

@ -0,0 +1,8 @@
#ifndef SOLVE_H
#define SOLVE_H
#include <stddef.h>
int t1_solve(char **a, int n, char *x, int (*cmp)(const char *, const char *));
#endif

23
2025.02.28/01Ex/sort.c Normal file
View file

@ -0,0 +1,23 @@
#include "sort.h"
int up_strcmp(const char *a, const char *b)
{ return strcmp(a, b); }
int down_strcmp(const char *a, const char *b)
{ return -strcmp(a, b); }
int up_len(const char *a, const char *b)
{
int i = 0;
while (1)
{
if (a[i] == '\0' && b[i] == '\0') return strcmp(a, b);
else if (a[i] == '\0') return -1;
else if (b[i] == '\0') return 1;
i++;
}
}
int down_len(const char *a, const char *b)
{ return -up_len(a, b); }

11
2025.02.28/01Ex/sort.h Normal file
View file

@ -0,0 +1,11 @@
#ifndef SORT_H
#define SORT_H
#include <string.h>
int up_strcmp(const char *a, const char *b);
int down_strcmp(const char *a, const char *b);
int up_len(const char *a, const char *b);
int down_len(const char *a, const char *b);
#endif