diff --git a/kp6/convert_to_binary.c b/kp6/convert_to_binary.c new file mode 100644 index 00000000..b1ced455 --- /dev/null +++ b/kp6/convert_to_binary.c @@ -0,0 +1,40 @@ +#include +#include "schedule.h" +// gcc convert_to_binary.c +// ./a.exe output.bin data.txt +int main(int argc, char *argv[]) { + schedule t; + FILE *file_out = NULL; + FILE *file_in = NULL; + + if (argc != 3) { + printf("Usage: %s output.bin data.txt\n", argv[0]); + return 1; + } + + file_out = fopen(argv[1], "wb"); + if (file_out == NULL) { + printf("Error with %s\n", argv[1]); + return 1; + } + file_in = fopen(argv[2], "r"); + if (file_in == NULL) { + printf("Error with %s\n", argv[2]); + return 1; + } + + while (!feof(file_in)) { + fscanf(file_in, "%d %s %d %s %d %d", + &t.group_number, + t.day, + &t.lesson_number, + t.subject, + &t.room_number, + &t.week + ); + fwrite(&t, sizeof(t), 1, file_out); + } + fclose(file_out); + fclose(file_in); + return 0; +} \ No newline at end of file diff --git a/kp6/main.c b/kp6/main.c new file mode 100644 index 00000000..3eb010f3 --- /dev/null +++ b/kp6/main.c @@ -0,0 +1,74 @@ +#include +#include +#include +#include "schedule.h" + +// gcc main.c +// ./a.exe output.bin -f +// ./a.exe output.bin -p 100 +int main(int argc, char *argv[]) +{ + schedule t; + FILE *file = NULL; + + if (argc < 3) + { + printf("Usage: %s \nFlags:\n-f - show all schedule\n-p - show schedule in the particular classroom\n", argv[0]); + return 1; + } + + file = fopen(argv[1], "rb"); + + if (file == NULL) + { + printf("Error with %s\n", argv[1]); + + return 1; + } + + if (!strcmp(argv[2], "-f")) + { + printf(" ____________________________________________________________________________________________________________________\n"); + printf("| Группа | день недели | номер пары | предмет | номер аудитории | неделя (чет/нечет) |\n"); + printf("`--------------`-------------------`------------------`-----------------`-----------------------`--------------------`\n"); + + while (fread(&t, sizeof(t), 1, file) == 1) + { + printf("|%14d|%19s|%18d|%17s|%23d|%20d|\n", + t.group_number, + t.day, + t.lesson_number, + t.subject, + t.room_number, + t.week + ); + + printf("`--------------`-------------------`------------------`-----------------`-----------------------`--------------------`\n"); + } + } else if (!strcmp(argv[2], "-p")) { + int requiredRoomNumber = atoi(argv[3]); + printf(" ____________________________________________________________________________________________________________________\n"); + printf("| Группа | день недели | номер пары | предмет | номер аудитории | неделя (чет/нечет) |\n"); + printf("`--------------`-------------------`------------------`-----------------`-----------------------`--------------------`\n"); + + while (fread(&t, sizeof(t), 1, file) == 1) { + if (t.room_number == requiredRoomNumber ) { + printf("|%14d|%19s|%18d|%17s|%23d|%20d|\n", + t.group_number, + t.day, + t.lesson_number, + t.subject, + t.room_number, + t.week + ); + printf("`--------------`-------------------`------------------`-----------------`-----------------------`--------------------`\n"); + } + } + } else { + printf("Usage: %s \nFlags:\n-f - show all data base\n-p - show teams with proven research-doc\n", argv[0]); + return 0; + } + fclose(file); + + return 0; +} \ No newline at end of file diff --git a/kp6/schedule.h b/kp6/schedule.h new file mode 100644 index 00000000..4c18d995 --- /dev/null +++ b/kp6/schedule.h @@ -0,0 +1,14 @@ +#ifndef __SCHEDULE__ +#define __SCHEDULE__ +#include + + +typedef struct schedule { + char day[30]; + char subject[30]; + int group_number; + int lesson_number; + int room_number; + int week; +} schedule; +#endif \ No newline at end of file diff --git a/lab1/lab1.txt b/lab1/lab1.txt new file mode 100644 index 00000000..d3f883d7 --- /dev/null +++ b/lab1/lab1.txt @@ -0,0 +1 @@ +listing kbkbkb diff --git a/lab6 b/lab6 new file mode 100644 index 00000000..69a3e9ef Binary files /dev/null and b/lab6 differ diff --git a/lab6.jdt b/lab6.jdt new file mode 100644 index 00000000..d9d1817c Binary files /dev/null and b/lab6.jdt differ diff --git a/laba25-26/Makefile b/laba25-26/Makefile new file mode 100644 index 00000000..4a97b24b --- /dev/null +++ b/laba25-26/Makefile @@ -0,0 +1,12 @@ +lab26: main.o stack.o test.o sort.o + gcc -o lab26 main.o stack.o test.o sort.o +main.o: main.c stack.h test.h sort.h + gcc -c main.c +test.o: test.c test.h stack.h sort.h + gcc -c test.c +sort.o: sort.c sort.h stack.h + gcc -c sort.c +stack.o: stack.c stack.h + gcc -c stack.c + + diff --git a/laba25-26/main.c b/laba25-26/main.c new file mode 100644 index 00000000..fad8bdbb --- /dev/null +++ b/laba25-26/main.c @@ -0,0 +1,9 @@ +#include +#include +#include "stack.h" +#include "test.h" +#include "sort.h" + +int main() { + test(); +} \ No newline at end of file diff --git a/laba25-26/sort.c b/laba25-26/sort.c new file mode 100644 index 00000000..ebd11d82 --- /dev/null +++ b/laba25-26/sort.c @@ -0,0 +1,26 @@ +#include +#include "stack.h" +#include "sort.h" + +void Sort(Stack** stack) { + if (Size(*stack) <= 1) { + return; + } + + Stack* sortedStack = InitStack(); + Stack* tempStack = InitStack(); + + while (!IsEmpty(*stack)) { + T maxItem = ExtractMax(*stack, tempStack); + Push(sortedStack, maxItem); + + + while (!IsEmpty(tempStack)) { + Push(*stack, Pop(tempStack)); + } + } + + DelStack(stack); + *stack = sortedStack; + DelStack(&tempStack); +} diff --git a/laba25-26/sort.h b/laba25-26/sort.h new file mode 100644 index 00000000..efe5091f --- /dev/null +++ b/laba25-26/sort.h @@ -0,0 +1,7 @@ +#ifndef __SORT__ +#define __SORT__ +#include "stack.h" + +void Sort(Stack** stack); + +#endif \ No newline at end of file diff --git a/laba25-26/stack.c b/laba25-26/stack.c new file mode 100644 index 00000000..5516334a --- /dev/null +++ b/laba25-26/stack.c @@ -0,0 +1,99 @@ +#include +#include +#include "stack.h" + +#define LEN 10 + +Stack* InitStack() { + Stack* stack = (Stack*)malloc(sizeof(Stack)); + stack->array = (T*)malloc(sizeof(T) * LEN); + stack->maxLen = LEN; + stack->index = -1; + return stack; +} + +int IsEmpty(Stack* stack) { + if (stack == NULL) { + return 1; + } + if (stack->index == -1) { + return 1; + } else { + return 0; + } +} + +void Push(Stack* stack, T value) { + if (stack == NULL) { + return; + } + stack->index++; + if (stack->index >= stack->maxLen) { + stack->array = realloc(stack->array, sizeof(T) * stack->maxLen * 2); + stack->maxLen = stack->maxLen * 2; + } + (stack->array)[stack->index] = value; +} + + +int Size(Stack* stack) { + if (stack == NULL) { + return 0; + } + return stack->index + 1; +} + +void DelStack(Stack** stack) { + if (*stack == NULL) { + return; + } + free((*stack)->array); + free(*stack); + *stack = NULL; +} + + +void PrintStack(Stack* stack) { + if (stack == NULL) { + return; + } + printf("start\n"); + if (stack->index == -1) { + printf("empty\n"); + } else { + for(int i = stack->index; i != -1; i--) { + printf("%d\n", (stack->array)[i]); + } + } + printf("end\n"); +} + +T Pop(Stack* stack) { + if (IsEmpty(stack)) { + printf("Error"); + return 0; + } + stack->index--; + return (stack->array)[stack->index + 1]; +} + +T ExtractMax(Stack* sourceStack, Stack* tempStack) { + if (IsEmpty(sourceStack)) { + printf("Error"); + return 0; + } + + T maxItem = Pop(sourceStack); + + while (!IsEmpty(sourceStack)) { + T item = Pop(sourceStack); + if (item > maxItem) { + Push(tempStack, maxItem); + maxItem = item; + } else { + Push(tempStack, item); + } + } + + return maxItem; +} diff --git a/laba25-26/stack.h b/laba25-26/stack.h new file mode 100644 index 00000000..b291df3d --- /dev/null +++ b/laba25-26/stack.h @@ -0,0 +1,22 @@ +#ifndef __STACK__ +#define __STACK__ + +typedef int T; + +typedef struct Stack { + T* array; + int index; + int maxLen; +} Stack; + +Stack* InitStack(); +int IsEmpty(Stack* stack); +void Push(Stack* stack, T value); +T Pop(Stack* stack); +int Size(Stack* stack); +void DelStack(Stack** stack); +void PrintStack(Stack* stack); +T ExtractMax(Stack* sourceStack, Stack* tempStack); + + +#endif \ No newline at end of file diff --git a/laba25-26/test.c b/laba25-26/test.c new file mode 100644 index 00000000..73c65c2f --- /dev/null +++ b/laba25-26/test.c @@ -0,0 +1,60 @@ +#include +#include +#include "stack.h" +#include "sort.h" +#include "test.h" + +void test () { + char command = ' '; + int ind; + int arg; + Stack* stacks[5] = {NULL, NULL, NULL, NULL, NULL}; + printf("i - init\n"); + printf("u - push\n"); + printf("o - pop\n"); + printf("s - stop\n"); + printf("d - del stack\n"); + printf("l - line sort\n"); + while (command != 's') { + scanf("%c", &command); + switch (command) { + case 'i': { + scanf("%d", &ind); + stacks[ind] = InitStack(); + break; + } + case 'u': { + scanf("%d %d", &ind, &arg); + Push(stacks[ind], arg); + PrintStack(stacks[ind]); + break; + } + case 'o': { + scanf("%d", &ind); + printf("pop %d\n", Pop(stacks[ind])); + PrintStack(stacks[ind]); + break; + } + case 's': { + for (int i = 0; i < 5; i++) { + if (stacks[i] != NULL) DelStack(&(stacks[i])); + } + break; + } + + case 'd': { + scanf("%d", &ind); + DelStack(&(stacks[ind])); + break; + } + + case 'l': { + scanf("%d", &ind); + Sort(&(stacks[ind])); + PrintStack(stacks[ind]); + break; + } + } + } + return; +} \ No newline at end of file diff --git a/laba25-26/test.h b/laba25-26/test.h new file mode 100644 index 00000000..dba6a9da --- /dev/null +++ b/laba25-26/test.h @@ -0,0 +1,8 @@ +#ifndef __TEST__ +#define __TEST__ +#include "stack.h" +#include "sort.h" + +void test(); + +#endif \ No newline at end of file diff --git a/photolab.png b/photolab.png new file mode 100644 index 00000000..b7282cd8 Binary files /dev/null and b/photolab.png differ