From b713b8928f4e2889fbafda88721ce2ce5f621b21 Mon Sep 17 00:00:00 2001 From: Guslik5 <91369419+Guslik5@users.noreply.github.com> Date: Sat, 18 Dec 2021 14:00:51 +0300 Subject: [PATCH 1/6] create laba_6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit от Гусаченко Дмитрия --- lab6/laba_6.c | 206 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 lab6/laba_6.c diff --git a/lab6/laba_6.c b/lab6/laba_6.c new file mode 100644 index 00000000..09a4bd09 --- /dev/null +++ b/lab6/laba_6.c @@ -0,0 +1,206 @@ +#include +#include +#include + +unsigned int Back_Change_Size(unsigned char size[4]) +{ + unsigned int res = 0; + for (int i = 0; i < 4; i++) + res += size[3 - i] << (8 * i); + return res; +} + +void Change_Size(unsigned int size, unsigned char *res) +{ + // printf("%d", size); + for (int i = 0; i < 4; i++) + { + res[i] = (size << (8 * i)) >> 24; + } +} + +void extract(FILE *arhive) +{ + FILE *file; + char sim; + sim = fgetc(arhive); + fseek(arhive, 0, SEEK_SET); + while (!feof(arhive)) + { + if (sim == EOF) + break; + + char arr_size_fileName[4]; + fread(arr_size_fileName, sizeof(char), sizeof(arr_size_fileName), arhive); + int size_fileName_int = Back_Change_Size(arr_size_fileName); + char arr_fileName[size_fileName_int + 1]; + fread(arr_fileName, sizeof(char), size_fileName_int, arhive); + arr_fileName[size_fileName_int] = '\0'; + file = fopen(arr_fileName, "wb"); + char arr_size_file[4]; + fread(arr_size_file, sizeof(char), sizeof(arr_size_file), arhive); + unsigned long long size_file_int = Back_Change_Size(arr_size_file); + for (int i = 0; i < size_file_int; i++) + { + sim = fgetc(arhive); + fputc(sim, file); + } + sim = fgetc(arhive); + fseek(arhive, -1, SEEK_CUR); + printf("\nextract: "); + for (int i = 0; i < size_fileName_int; i++) + { + printf("%c", arr_fileName[i]); + } + } + fclose(arhive); +} + +void list(FILE *arhive) +{ + int counter_files = 0; + char sim = fgetc(arhive); + fseek(arhive, 0, SEEK_SET); + // fseek(arhive, 0, SEEK_END); + // long long size_file = ftell(arhive); + // fseek(arhive, 0, SEEK_SET); + while (!feof(arhive)) + { + if (sim == EOF) + break; + char arr_size_fileName[4]; + fread(arr_size_fileName, sizeof(char), sizeof(arr_size_fileName), arhive); + int size_fileName_int = Back_Change_Size(arr_size_fileName); + char arr_fileName[size_fileName_int]; + fread(arr_fileName, sizeof(char), size_fileName_int, arhive); + char arr_size_file[4]; + fread(arr_size_file, sizeof(char), sizeof(arr_size_file), arhive); + unsigned long long size_file_int = Back_Change_Size(arr_size_file); + fseek(arhive, size_file_int, SEEK_CUR); + counter_files++; + printf("%d)",counter_files); + for (int i = 0; i < size_fileName_int; i++) + { + printf("%c", arr_fileName[i]); + } + printf(" size: %lli\n", size_file_int); + sim = fgetc(arhive); + fseek(arhive, -1, SEEK_CUR); + + } + printf(" <>", counter_files); +} + +void creat(FILE *arhive, char *file_name) +{ + char sim; + FILE *file; + file = fopen(file_name, "rb"); + if (file == NULL) + { + printf("\nerror: file "); + for (int i = 0; i < strlen(file_name); i++) + { + printf("%c", file_name[i]); + } + + printf(" not found"); + } + else + { + fseek(file, 0, SEEK_END); + unsigned long long size_file_int = ftell(file); + fseek(file, 0, SEEK_SET); + char arr_size_file[4]; + Change_Size(size_file_int, arr_size_file); + + char arr_size_fileName[4]; + int size_fileName_int = strlen(file_name); + Change_Size(size_fileName_int, arr_size_fileName); + + fwrite(arr_size_fileName, sizeof(char), sizeof(arr_size_fileName), arhive); + fwrite(file_name, sizeof(char), size_fileName_int, arhive); + fwrite(arr_size_file, sizeof(char), sizeof(arr_size_file), arhive); + for (int i = 0; i < size_file_int; i++) + { + sim = fgetc(file); + fputc(sim, arhive); + } + + printf("\nadd: "); + for (int i = 0; i < size_fileName_int; i++) + { + printf("%c", file_name[i]); + } + fclose(file); + remove(file_name); + } +} +// 1085176 12048461 + + +int main(int argc, char **argv) +{ + FILE *file; + FILE *arhive ;//= fopen("arhive.arc", "rb"); + // char file_name[] = "tib.mp3"; + // char file_name2[] = "file2.txt"; + // char file_name3[] = "bitok.mp3"; + char *arhive_name; + if (argc < 4) + { + printf("error\n invalid numbers arguments"); + return 1; + } + for (int i = 0; i < argc; i++) + { + if (!strcmp(argv[i], "--file")) + { + arhive_name = argv[i + 1]; + } + + if (!strcmp(argv[i], "--create")) + { + printf("\n============================== create ==============================\n"); + arhive = fopen(arhive_name, "ab"); + for (int i = 4; i < argc; i++) + { + creat(arhive, argv[i]); + } + fclose(arhive); + printf("\n====================================================================\n"); + } + if (!strcmp(argv[i], "--list")) + { + printf("=============================== list ===============================\n"); + arhive = fopen(arhive_name, "rb"); + list(arhive); + fclose(arhive); + printf("\n====================================================================\n"); + } + if (!strcmp(argv[i], "--extract")) + { + printf("\n============================== extract ==============================\n"); + arhive = fopen(arhive_name, "rb"); + extract(arhive); + fclose(arhive); + remove(arhive_name); + printf("\n=====================================================================\n"); + // if (remove(arhive_name) != 0) + // { + // printf("no") ; + // } + // else + // printf("yes"); + } + } + + // arc --file data.arc --create a.txt b.bin c.bmp + + // creat(arhive, file_name); + // creat(arhive,file_name2); + // creat(arhive,file_name3); + // list(arhive); + // extract(arhive); + return 0; +} From 199c37391956cece02ee82afe49c6bbd6b96ebe6 Mon Sep 17 00:00:00 2001 From: Guslik5 <91369419+Guslik5@users.noreply.github.com> Date: Sat, 18 Dec 2021 15:47:48 +0300 Subject: [PATCH 2/6] Create laba_3.c --- lab3/laba_3.c | 215 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 lab3/laba_3.c diff --git a/lab3/laba_3.c b/lab3/laba_3.c new file mode 100644 index 00000000..e6131cd9 --- /dev/null +++ b/lab3/laba_3.c @@ -0,0 +1,215 @@ +#include +#include +#include +#include +#include +#include + +int size = 0; +typedef struct queue +{ + long long value; + struct queue *next; +} queue_c; + +queue_c *head = NULL; +queue_c *tail = NULL; + +queue_c *push(long long x) +{ + queue_c *ptr = (queue_c *)malloc(sizeof(queue_c)); + if (head != NULL) + { + tail->next = ptr; + ptr->value = x; + ptr->next = NULL; + tail = ptr; + } + else + { + ptr->value = x; + ptr->next = NULL; + tail = ptr; + head = ptr; + } + size++; +} + +void pop() +{ + if (head != NULL) + { + queue_c *temp = head->next; + free(head); + head = temp; + } + size--; +} + +int main(int argc, char **argv) +{ + if (argc != 3) + { + printf("ERROR: invalid number of arguments"); + return 1; + } + FILE *fin; + fin = fopen(argv[1], "r"); + if (fin == NULL) + { + printf("ERROR: the file does not exist"); + return 1; + } + long long counter = 0; + char sim; + long long second = atoi(argv[2]); + long long right_max; + long long left_max; + long long count_request = 0; + char request[1000]; + char month[4]; + long long time_1 = 0; + long long time_2 = 0; + int max = 0; + int a = 0; + struct tm *time = (struct tm *)malloc(sizeof(struct tm)); + while (sim != EOF) + { + while ((sim != '[') && (sim !=EOF)) + { + sim = fgetc(fin); + } + + if (sim == '[') + { + time -> tm_mday = (fgetc(fin) - 48) * 10 + fgetc(fin) - 48; + + sim = fgetc(fin); + month[0] = fgetc(fin); + month[1] = fgetc(fin); + month[2] = fgetc(fin); + if (strcmp(month, "Jan") == 0) + time->tm_mon = 0; + if (strcmp(month, "Feb") == 0) + time->tm_mon = 1; + if (strcmp(month, "Mar") == 0) + time->tm_mon = 2; + if (strcmp(month, "Apr") == 0) + time->tm_mon = 3; + if (strcmp(month, "May") == 0) + time->tm_mon = 4; + if (strcmp(month, "Jun") == 0) + time->tm_mon = 5; + if (strcmp(month, "Jul") == 0) + time->tm_mon = 6; + if (strcmp(month, "Aug") == 0) + time->tm_mon = 7; + if (strcmp(month, "Sep") == 0) + time->tm_mon = 8; + if (strcmp(month, "Oct") == 0) + time->tm_mon = 9; + if (strcmp(month, "Nov") == 0) + time->tm_mon = 10; + if (strcmp(month, "Dec") == 0) + time->tm_mon = 11; + + sim = fgetc(fin); + time->tm_year = (fgetc(fin) - 48) * 1000 + (fgetc(fin) - 48) * 100 + (fgetc(fin) - 48) * 10 + (fgetc(fin) - 48) - 1900;; + sim = fgetc(fin); + time->tm_hour = (fgetc(fin) - 48) * 10 + (fgetc(fin) - 48); + sim = fgetc(fin); + time->tm_min = (fgetc(fin) - 48) * 10 + (fgetc(fin) - 48); + sim = fgetc(fin); + time->tm_sec = (fgetc(fin) - 48) * 10 + (fgetc(fin) - 48); + sim = fgetc(fin); + + time_1 = mktime(time); + if (max == 0) + { + push(time_1); + time_2 = time_1; + count_request++; + } + else + { + if (time_1 - time_2 <= second) + { + push(time_1); + count_request++; + } + else + { + while ((time_1 - time_2 > second) && (size != 0)) + { + pop(); + count_request--; + if (size != 0) + time_2 = head->value; + } + push(time_1); + count_request++; + if (size == 1) + time_2 = time_1; + } + } + } + + while ((sim != '\"') && (sim != EOF)) + { + sim = fgetc(fin); + } + + if (max < count_request) + { + max = count_request; + left_max = time_2; + right_max = time_1; + } + + //поиск количества ошибок и сами реквесты + if (sim == '\"') + { + sim = fgetc(fin); + long long i = 0; + while (sim != '\"') + { + request[i] = sim; + i++; + sim = fgetc(fin); + } + sim = fgetc(fin); + sim = fgetc(fin); + //if ((sim != '1') && (sim != '2')) + //{ + //counter++; + if (sim == '5') + { + counter++; + int j; + for (j = 0; j < i; j++) + { + printf("%c", request[j]); + } + printf("\n"); + } + //while (sim != '\n') + //{ + // sim = fgetc(fin); + //} + //} + } + while ((sim != '\n') && (sim != EOF)) + { + sim = fgetc(fin); + } + } + printf("count of error %i\n", counter); + printf("maximum number of requests per % lli seconds:", second); + printf("% lli \n", max); + time = localtime(&left_max); + // time = &left_max; + printf("from:\n %s", asctime(time)); + time = localtime(&right_max); + printf("until:\n %s", asctime(time)); + return 0; +} From fd7d18c2e079df7189052bc2e4f99fe8b5effcc8 Mon Sep 17 00:00:00 2001 From: Guslik5 <91369419+Guslik5@users.noreply.github.com> Date: Sat, 18 Dec 2021 16:23:18 +0300 Subject: [PATCH 3/6] Create laba_3_final --- lab3/laba_3_final | 215 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 lab3/laba_3_final diff --git a/lab3/laba_3_final b/lab3/laba_3_final new file mode 100644 index 00000000..e6131cd9 --- /dev/null +++ b/lab3/laba_3_final @@ -0,0 +1,215 @@ +#include +#include +#include +#include +#include +#include + +int size = 0; +typedef struct queue +{ + long long value; + struct queue *next; +} queue_c; + +queue_c *head = NULL; +queue_c *tail = NULL; + +queue_c *push(long long x) +{ + queue_c *ptr = (queue_c *)malloc(sizeof(queue_c)); + if (head != NULL) + { + tail->next = ptr; + ptr->value = x; + ptr->next = NULL; + tail = ptr; + } + else + { + ptr->value = x; + ptr->next = NULL; + tail = ptr; + head = ptr; + } + size++; +} + +void pop() +{ + if (head != NULL) + { + queue_c *temp = head->next; + free(head); + head = temp; + } + size--; +} + +int main(int argc, char **argv) +{ + if (argc != 3) + { + printf("ERROR: invalid number of arguments"); + return 1; + } + FILE *fin; + fin = fopen(argv[1], "r"); + if (fin == NULL) + { + printf("ERROR: the file does not exist"); + return 1; + } + long long counter = 0; + char sim; + long long second = atoi(argv[2]); + long long right_max; + long long left_max; + long long count_request = 0; + char request[1000]; + char month[4]; + long long time_1 = 0; + long long time_2 = 0; + int max = 0; + int a = 0; + struct tm *time = (struct tm *)malloc(sizeof(struct tm)); + while (sim != EOF) + { + while ((sim != '[') && (sim !=EOF)) + { + sim = fgetc(fin); + } + + if (sim == '[') + { + time -> tm_mday = (fgetc(fin) - 48) * 10 + fgetc(fin) - 48; + + sim = fgetc(fin); + month[0] = fgetc(fin); + month[1] = fgetc(fin); + month[2] = fgetc(fin); + if (strcmp(month, "Jan") == 0) + time->tm_mon = 0; + if (strcmp(month, "Feb") == 0) + time->tm_mon = 1; + if (strcmp(month, "Mar") == 0) + time->tm_mon = 2; + if (strcmp(month, "Apr") == 0) + time->tm_mon = 3; + if (strcmp(month, "May") == 0) + time->tm_mon = 4; + if (strcmp(month, "Jun") == 0) + time->tm_mon = 5; + if (strcmp(month, "Jul") == 0) + time->tm_mon = 6; + if (strcmp(month, "Aug") == 0) + time->tm_mon = 7; + if (strcmp(month, "Sep") == 0) + time->tm_mon = 8; + if (strcmp(month, "Oct") == 0) + time->tm_mon = 9; + if (strcmp(month, "Nov") == 0) + time->tm_mon = 10; + if (strcmp(month, "Dec") == 0) + time->tm_mon = 11; + + sim = fgetc(fin); + time->tm_year = (fgetc(fin) - 48) * 1000 + (fgetc(fin) - 48) * 100 + (fgetc(fin) - 48) * 10 + (fgetc(fin) - 48) - 1900;; + sim = fgetc(fin); + time->tm_hour = (fgetc(fin) - 48) * 10 + (fgetc(fin) - 48); + sim = fgetc(fin); + time->tm_min = (fgetc(fin) - 48) * 10 + (fgetc(fin) - 48); + sim = fgetc(fin); + time->tm_sec = (fgetc(fin) - 48) * 10 + (fgetc(fin) - 48); + sim = fgetc(fin); + + time_1 = mktime(time); + if (max == 0) + { + push(time_1); + time_2 = time_1; + count_request++; + } + else + { + if (time_1 - time_2 <= second) + { + push(time_1); + count_request++; + } + else + { + while ((time_1 - time_2 > second) && (size != 0)) + { + pop(); + count_request--; + if (size != 0) + time_2 = head->value; + } + push(time_1); + count_request++; + if (size == 1) + time_2 = time_1; + } + } + } + + while ((sim != '\"') && (sim != EOF)) + { + sim = fgetc(fin); + } + + if (max < count_request) + { + max = count_request; + left_max = time_2; + right_max = time_1; + } + + //поиск количества ошибок и сами реквесты + if (sim == '\"') + { + sim = fgetc(fin); + long long i = 0; + while (sim != '\"') + { + request[i] = sim; + i++; + sim = fgetc(fin); + } + sim = fgetc(fin); + sim = fgetc(fin); + //if ((sim != '1') && (sim != '2')) + //{ + //counter++; + if (sim == '5') + { + counter++; + int j; + for (j = 0; j < i; j++) + { + printf("%c", request[j]); + } + printf("\n"); + } + //while (sim != '\n') + //{ + // sim = fgetc(fin); + //} + //} + } + while ((sim != '\n') && (sim != EOF)) + { + sim = fgetc(fin); + } + } + printf("count of error %i\n", counter); + printf("maximum number of requests per % lli seconds:", second); + printf("% lli \n", max); + time = localtime(&left_max); + // time = &left_max; + printf("from:\n %s", asctime(time)); + time = localtime(&right_max); + printf("until:\n %s", asctime(time)); + return 0; +} From 9d6a051a86475be281023d6f3aefe5b77fc7d938 Mon Sep 17 00:00:00 2001 From: Guslik5 <91369419+Guslik5@users.noreply.github.com> Date: Sat, 15 Jan 2022 13:17:53 +0300 Subject: [PATCH 4/6] Create laba2.c --- lab2/laba2.c | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 lab2/laba2.c diff --git a/lab2/laba2.c b/lab2/laba2.c new file mode 100644 index 00000000..2228b557 --- /dev/null +++ b/lab2/laba2.c @@ -0,0 +1,172 @@ +#include +#include + +typedef struct Num +{ + unsigned int arr[32]; +} Num; + +Num uint1024_t_from_uint(unsigned int value) // перевод числа в uint1024 +{ + Num res; + for (int i = 0; i < 31; i++) + res.arr[i] = 0; + res.arr[31] = value; + return res; +} +Num add_op(Num value1, Num value2) // cложение uint1024 +{ + Num res; + for (int i = 0; i < 32; i++) // зануляем + res.arr[i] = 0; + res.arr[0] += value1.arr[0] + value2.arr[0]; // мы не можем проверить на переполнение, поэтому делаем это сразу(отрежем если переполнение) + for (int i = 31; i > 0; i--) + { + res.arr[i] += value1.arr[i] + value2.arr[i]; + if ((value1.arr[i] > res.arr[i]) && (value2.arr[i] > res.arr[i])) // проверяем на переполнение + res.arr[i - 1]++; // тк при сложении может быть переполнение только на 1 + } + + return res; +} +Num subtr_op(Num value, Num y) //разность +{ + Num res; + for (int i = 0; i < 32; i++) // зануляем + res.arr[i] = 0; + res.arr[0] += value.arr[0] - y.arr[0]; + for (int i = 31; i >= 0; i--) + { + res.arr[i] += value.arr[i] - y.arr[i]; + if (res.arr[i] > value.arr[i]) // проверяем переполнение + res.arr[i - 1]--; + } + + return res; +} +Num multiplication(Num value, unsigned int value_int) // Произведение с unsigned int +{ + Num res; + for (int i = 0; i < 32; i++) // зануляем + res.arr[i] = 0; + unsigned long long a = value_int; + for (int i = 31; i >= 0; i--) + { + unsigned long long composition; + unsigned long long b = value.arr[i]; + composition = a * b; // перемножение интов не даст больше лонга, переполнения тут не будет, но нужно учесть, что в лонге как бы другая система счисления + res.arr[i] += composition % 4294967296; // делим на систему(как бы обратный перевод) + if (i != 0) // переполнение + res.arr[i - 1] += composition / 4294967296; + } + return res; +} +Num mult_op(Num value, Num value2) //Произведение uint1024 +{ + Num res; + for (int i = 0; i < 32; i++) // зануляем + res.arr[i] = 0; + for (int i = 31; i >= 0; i--) + { + if (value2.arr[i] != 0) + { + Num temp = multiplication(value, value2.arr[i]); + int k = 31 - i; + for (int j = k; j < 32; j++) // сдвигаем на разряд при умножении + { + temp.arr[j - k] = temp.arr[j]; + } + for (int j = 32 - k; j < 32; j++) + { + temp.arr[j] = 0; + } + res = add_op(res, temp); + } + } + return res; +} +void printf_value(Num value) //вывод +{ + char buf[1024] = {0}; + for (int i = 0; i < 1024; i++) + { + + Num res; + for (int i = 0; i < 32; i++) + { + res.arr[i] = 0; + } + unsigned long long remains = 0; + for (int i = 0; i < 32; i++) // находим остаток от деления на 10 и делим на 10 + { + res.arr[i] = (remains * 4294967296 + value.arr[i]) / 10; + remains = (remains * 4294967296 + value.arr[i]) % 10; + } + unsigned mod = remains; + value = res; // после деления на 10 + + buf[1023 - i] = mod + '0'; // записываем чарами с конца + } + + unsigned begin = 0; + while (buf[begin] == '0') //пропускаем ненужные 0 в начале + begin++; + if (begin != 1024) //если все 0, значит число 0 + for (int i = begin; i < 1024; i++) // выписываем начиная с момента, когда встретим первую цифру + { + printf("%c", buf[i]); + } + else + { + printf("0"); + } +} +void scanf_value(Num *value) //ввод +{ + char buffer[1024]; + scanf("%s", buffer); + int counter = 0; + for (int i = 0; i < 32; i++) // зануляем + value->arr[i] = 0; + while (buffer[counter] != '\0' && counter < 1024) // пока не дойдем до конца или не выйдем за 1024 + { + Num templete; + for (int i = 0; i < 32; i++) // зануляем + templete.arr[i] = 0; + for (int i = 31; i >= 0; i--) + { + unsigned long long composition; + unsigned long long a = value->arr[i]; + composition = a * 10; + templete.arr[i] += composition % 4294967296; + if (i != 0) // переполнение + templete.arr[i - 1] += composition / 4294967296; + } + *value = templete; + Num temp = uint1024_t_from_uint(buffer[counter] - '0'); //перевод символа в uint1024 + *value = add_op(*value, temp); + counter++; + } +} + +int main() +{ + Num a; + Num b; + Num temp; + printf("Введите первое число: "); + scanf_value(&a); + printf("\n"); + printf("Введите второе число: "); + scanf_value(&b); + printf("\nСумма: "); + temp = add_op(a, b); + printf_value(temp); + printf("\nРазность: "); + temp = subtr_op(a, b); + printf_value(temp); + printf("\nПроизведение: "); + temp = mult_op(a, b); + printf_value(temp); + return 0; +} From c0a3685a44f0494c53cff802186d478aff606958 Mon Sep 17 00:00:00 2001 From: Guslik5 <91369419+Guslik5@users.noreply.github.com> Date: Tue, 15 Mar 2022 16:05:12 +0300 Subject: [PATCH 5/6] dop_laba_3.c --- lab3/laba_3_dop.c | 153 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 lab3/laba_3_dop.c diff --git a/lab3/laba_3_dop.c b/lab3/laba_3_dop.c new file mode 100644 index 00000000..854250b0 --- /dev/null +++ b/lab3/laba_3_dop.c @@ -0,0 +1,153 @@ +#include +#include +#include +#include + +int month_(char month[4]) +{ + int m; + if (strcmp(month, "Jan") == 0) + m = 0; + if (strcmp(month, "Feb") == 0) + m = 1; + if (strcmp(month, "Mar") == 0) + m = 2; + if (strcmp(month, "Apr") == 0) + m = 3; + if (strcmp(month, "May") == 0) + m = 4; + if (strcmp(month, "Jun") == 0) + m = 5; + if (strcmp(month, "Jul") == 0) + m = 6; + if (strcmp(month, "Aug") == 0) + m = 7; + if (strcmp(month, "Sep") == 0) + m = 8; + if (strcmp(month, "Oct") == 0) + m = 9; + if (strcmp(month, "Nov") == 0) + m = 10; + if (strcmp(month, "Dec") == 0) + m = 11; + return m; +} + +long long time_(FILE *file) +{ + struct tm *time; + char sim = fgetc(file); + while ((sim != '[') && (sim != EOF)) + sim = fgetc(file); + time->tm_mday = (fgetc(file) - 48) * 10 + fgetc(file) - 48; + sim = fgetc(file); + char month[4]; + month[0] = fgetc(file); + month[1] = fgetc(file); + month[2] = fgetc(file); + month[3] = '\0'; + time->tm_mon = month_(month); + sim = fgetc(file); + time->tm_year = (fgetc(file) - 48) * 1000 + (fgetc(file) - 48) * 100 + (fgetc(file) - 48) * 10 + (fgetc(file) - 48) - 1900; + sim = fgetc(file); + time->tm_hour = (fgetc(file) - 48) * 10 + (fgetc(file) - 48); + sim = fgetc(file); + time->tm_min = (fgetc(file) - 48) * 10 + (fgetc(file) - 48); + sim = fgetc(file); + time->tm_sec = (fgetc(file) - 48) * 10 + (fgetc(file) - 48); + sim = fgetc(file); + // long long mk_time = mktime(time); + return mktime(time); +} + +int main(int argc, char **argv) +{ + struct tm *time = (struct tm *)malloc(sizeof(struct tm)); + char request[1000]; + long long counter = 0; + // FILE *file1 = fopen("NASA_access_log_Jul95", "r"); + // FILE *file2 = fopen("NASA_access_log_Jul95", "r"); + // int second = 10; + + FILE *file1 = fopen(argv[1], "r"); + FILE *file2 = fopen(argv[1], "r"); + int second = atoi(argv[2]); + + char sim; + sim = fgetc(file1); + long long count = 0, time_l = 0, time_r = 0, max_time_l = 0, max_time_r = 0, max_count = 0; + while (sim != EOF) + { + if (count == 0) + { + time_l = time_(file2); + max_time_l = time_l; + } + time_r = time_(file1); + if (time_r - time_l > second) + { + if (count > max_count) + { + max_count = count; + max_time_l = time_l; + } + time_l = time_(file2); + } + else + count++; + + while ((sim != '"') && (sim != EOF)) + sim = fgetc(file1); + + if (sim == '\"') + { + sim = fgetc(file1); + long long i = 0; + while (sim != '\"') + { + request[i] = sim; + i++; + sim = fgetc(file1); + } + sim = fgetc(file1); + sim = fgetc(file1); + //если нужно считать, что ошибки это все кроме 1 и 2 + /*if ((sim != '1') && (sim != '2')) + { + counter++; + */ + if (sim == '5') + { + counter++; + int j; + for (j = 0; j < i; j++) + printf("%c", request[j]); + printf("\n"); + } + } + + if ((time_r < max_time_l + second) && (time_l == max_time_l)) + { + max_count = count; + max_time_l = time_l; + } + while ((sim != '\n') && (sim != EOF)) + sim = fgetc(file1); + } + /* +129.130.115.19 - - [27/Jul/1995:11:44:31 -0400] "POST /shuttle/missions/sts-69/mission-sts-69.html HTTP/1.0" 501 - +surg1.mayo.edu - - [27/Jul/1995:11:44:33 -0400] "GET /shuttle/missions/51-l/docs/ HTTP/1.0" 200 368 +surg1.mayo.edu - - [27/Jul/1995:11:44:36 -0400] "GET /shuttle/missions/51-l/ HTTP/1.0" 200 1712 +malin.space.se - - [27/Jul/1995:11:44:37 -0400] "GET /persons/nasa-cm/jmd.html HTTP/1.0" 200 3933 +news.ti.com - - [27/Jul/1995:11:44:39 -0400] "GET /history/apollo/images/apollo-logo1.gif HTTP/1.0" 200 1173 + */ + max_time_r = max_time_l + second; + printf("Ошибок с номером \"5\" %lli\n", counter); + printf("Максимально запросов в промежутке %d секунд:", second); + printf("%lli \n", max_count); + time = localtime(&max_time_l); + printf("с:\n %s", asctime(time)); + time = localtime(&max_time_r); + printf("по:\n %s", asctime(time)); + return 0; +} From 8a1a69743be422dd57ecfa2f7fc702d0136fd946 Mon Sep 17 00:00:00 2001 From: Guslik5 <91369419+Guslik5@users.noreply.github.com> Date: Tue, 15 Mar 2022 16:45:12 +0300 Subject: [PATCH 6/6] Create laba_5_dop.c --- lab5/laba_5_dop.c | 337 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 337 insertions(+) create mode 100644 lab5/laba_5_dop.c diff --git a/lab5/laba_5_dop.c b/lab5/laba_5_dop.c new file mode 100644 index 00000000..8985f66f --- /dev/null +++ b/lab5/laba_5_dop.c @@ -0,0 +1,337 @@ +#include +#include +#include +#include + +typedef struct BMP +{ + unsigned long long size; + unsigned long long width; + unsigned long long height; + unsigned char **arr; + // unsigned long long OLDsize; + // unsigned long long OLDwidth; + // unsigned long long OLDheight; + // unsigned char **OLDarr; + +} BMP; + +unsigned int Change_Size(unsigned char size[4]) +{ + unsigned int res = 0; + for (int i = 0; i < 4; i++) + res |= size[3 - i] << (8 * i); + return res; +} + +void Back_Change_Size(unsigned int size, unsigned char *res) +{ + // printf("%d", size); + for (int i = 1; i < 4; i++) + { + res[i] = (size << (8 * i)) >> 24; + } + res[0] = size >> 21; +} + +BMP Reading(char *filename) +{ + FILE *file; + file = fopen(filename, "rb"); + BMP Temp; + char buffer[62]; + unsigned long long checker = 0; + fread(buffer, 62, sizeof(char), file); + char temp1[4] = {buffer[21], buffer[20], buffer[19], buffer[18]}; + char temp2[4] = {buffer[25], buffer[24], buffer[23], buffer[22]}; + char temp3[4] = {buffer[5], buffer[4], buffer[3], buffer[2]}; + Temp.width = Change_Size(temp1); + Temp.height = Change_Size(temp2); + Temp.size = Change_Size(temp3); + Temp.arr = (unsigned char **)malloc(Temp.height * sizeof(unsigned char *)); + for (int i = 0; i < Temp.height; i++) + Temp.arr[i] = (unsigned char *)malloc(Temp.width * sizeof(unsigned char)); + if ((Temp.width % 8) != 0) + checker = Temp.width / 8 + 1; + else + checker = Temp.width / 8; + if (checker % 4 == 0) + { + for (int i = Temp.height - 1; i >= 0; i--) + for (int j = 0; j < checker; j++) + { + unsigned char byte = fgetc(file); + if (j != checker - 1) + for (int bit = 0; bit < 8; bit++) + Temp.arr[i][j * 8 + bit] = (byte >> (7 - bit)) % 2; + + else if (j == checker - 1) + { + for (int bit = 0; bit < Temp.width - (checker - 1) * 8; bit++) + Temp.arr[i][j * 8 + bit] = (byte >> (7 - bit)) % 2; + } + } + } + else + { + for (int i = Temp.height - 1; i >= 0; i--) + { + for (int j = 0; j < checker; j++) + { + unsigned char byte = fgetc(file); + if (j != checker - 1) + for (int bit = 0; bit < 8; bit++) + Temp.arr[i][j * 8 + bit] = (byte >> (7 - bit)) % 2; + else if (j == checker - 1) + { + for (int bit = 0; bit < Temp.width - (checker - 1) * 8; bit++) + Temp.arr[i][j * 8 + bit] = (byte >> (7 - bit)) % 2; + } + } + for (int k = 0; k < 4 - (checker % 4); k++) + fgetc(file); + } + } + for (int i = 0; i < 4; i++) + { + printf("\n"); + for (int j = 0; j < 10; j++) + { + printf("%d ", Temp.arr[i][j]); + } + } + printf("\n\n\n\n\n"); + + + return Temp; +} + +int findneighbors(BMP old, int y, int x) +{ + int cnt = 0; + + for (int dy = -1; dy <= 1; dy++) + for (int dx = -1; dx <= 1; dx++) + if (!(dy == 0 && dx == 0)) + { + if (old.arr[(y + dy + old.height) % old.height][(x + dx + old.width) % old.width] == 1) + { + cnt++; + // printf("%d$$", old.arr[y][x]); + // printf("%d %d", y, x); + // printf("^^%d %d", dy, dx); + // printf("|||"); + } + } + return cnt; +} + +void lifegame(BMP old, BMP new) +{ + int neigh; + // for (int i = 0; i < 4; i++) + // { + // // printf("\n"); + // // for (int j = 0; j < 10; j++) + // // { + // // printf("%d ", old.arr[i][j]); + // // } + // } + // printf("\n\n\n\n\n"); + for (int i = 0; i < old.height; i++) + { + for (int j = 0; j < old.width; j++) + { + neigh = findneighbors(old, i, j); + if (old.arr[i][j] == 1) + { + if (neigh >= 2 && neigh < 4) + new.arr[i][j] = 1; + else + new.arr[i][j] = 0; + } + else + { + if (neigh == 3) + new.arr[i][j] = 1; + else + new.arr[i][j] = 0; + } + } + } + for (int i = 0; i < 4; i++) + { + printf("\n"); + for (int j = 0; j < 10; j++) + { + printf("%d ", new.arr[i][j]); + } + } + printf("\n\n\n\n\n"); +} + +void Create(BMP old, char *file_old, char *file_new) +{ + BMP new; + new.size = old.size; + new.width = old.width; + new.height = old.height; + FILE *old_file = fopen(file_old, "rb"); + FILE *new_file = fopen(file_new, "wb"); + char buffer[62] = {0}; + fread(buffer, sizeof(char), 62, old_file); + fwrite(buffer, sizeof(char), 62, new_file); + + unsigned long long checker = 0; + if ((old.width % 8) == 0) + checker = old.width / 8; + else + checker = old.width / 8 + 1; + if (checker % 4 == 0) + { + for (int i = old.height - 1; i >= 0; i--) + for (int j = 0; j < checker; j++) + { + unsigned char byte = 0; + if (j != checker - 1) + for (int bit = 7; bit >= 0; bit--) + byte += old.arr[i][j * 8 + 7 - bit] << bit; + + else if (j == checker - 1) + { + for (int bit = 7; bit >= 8 - (int)(old.width - (checker - 1) * 8); bit--) + { + byte += old.arr[i][j * 8 + 7 - bit] << bit; + } + } + fputc(byte, new_file); + } + } + else + { + for (int i = old.height - 1; i >= 0; i--) + { + for (int j = 0; j < checker; j++) + { + unsigned char byte = 0; + if (j != checker - 1) + for (int bit = 7; bit >= 0; bit--) + byte += old.arr[i][j * 8 + 7 - bit] << bit; + + else if (j == checker - 1) + { + for (int bit = 7; bit >= 8 - (int)(old.width - (checker - 1) * 8); bit--) + byte += old.arr[i][j * 8 + 7 - bit] << bit; + } + fputc(byte, new_file); + } + for (int k = 0; k < 4 - (checker % 4); k++) + fputc(0, new_file); + } + } +} + +int main(int argc, char **argv) +{ + FILE *filename = "D:/university/laba_proga/laba_5/zm.bmp"; + char *directoryname = "D:/university/laba_proga/laba_5/"; + int max_iter = 5; + int dump_freq = 1; + char new_adress[100]; + char new_filename[100]; + int flag1 = 1; + int flag2 = 1; + // for (int i = 1; i < argc; i += 1) + // { //тут чтобы четко считывать все данные, я проверяю каждый аргумент на соотвествие тому, что в функции memcmp + // if (strcmp(argv[i], "--input") == 0) + // { + // filename = argv[i + 1]; //сюда название файла + // flag1++; //чекер сделан для проверки ниже, на случай, если у меня не будет дерриктории или файла (стока 273) + // } + // if (strcmp(argv[i], "--output") == 0) + // { + // directoryname = argv[i + 1]; //сюда дериктории для создания бмп + // flag2++; + // } + // if (strcmp(argv[i], "--max_iter") == 0) + // max_iter = atoi(argv[i + 1]); //количество итераций + // if (strcmp(argv[i], "--dump_freq") == 0) + // dump_freq = atoi(argv[i + 1]); //через сколько сохранять файл + // } + // if (flag1 != 1) + // { + // printf("error:\n not found file"); //та самая проверочка с чекером + // } + // if (flag2 != 1) + // { + // printf("error:\n not found file out"); //та самая проверочка с чекером + // } + BMP Bmp; + Bmp = Reading(filename); + BMP old; + BMP new; + old = Bmp; + new = Bmp; + for (int i = 0; i < max_iter; i++) + { + int counter = 1; + if (counter >= dump_freq) + { + memmove(new_adress, directoryname, strlen(directoryname)); + sprintf(new_filename, "%d", i + 1); + strncat(new_filename, ".bmp ", 5); + strncat(new_adress, new_filename, strlen(new_filename) + 1); + Create(old, filename, new_filename); + counter = 1; + } + + lifegame(old, new); + counter++; + + old = new; + } + + return 0; +} + +// char buffer[62]; +// fread(buffer, 62, sizeof(char), filename); +// //временные массивы для более удобного перевода +// char temp1[4] = {buffer[21], buffer[20], buffer[19], buffer[18]}; +// char temp2[4] = {buffer[25], buffer[24], buffer[23], buffer[22]}; +// char temp3[4] = {buffer[5], buffer[4], buffer[3], buffer[2]}; +// // перевод через побитовый сдвиг +// Photo.width = Change_Size(temp1); +// Photo.height = Change_Size(temp2); +// Photo.size = Change_Size(temp3); +// // выделение памяти и считывание файла +// unsigned char *Data = (unsigned char *)malloc((Photo.size - 62) * sizeof(unsigned char)); +// fread(Data, sizeof(unsigned char), Photo.size, file); +// int **mas = (int **)malloc(Photo.height * sizeof(int *)); +// for (int i = 0; i < Photo.height; i++) +// mas[i] = (int *)malloc(Photo.width * sizeof(int)); +// int k = 0; +// for (int i = Photo.height - 1; i >= 0; i--) +// { +// for (int j = 0; j < Photo.width; j++) +// { +// if (Data[k] == 255) +// { +// printf("%d ", Data[k]); +// mas[i][j] = 0; +// } +// else +// { +// printf("%d ", Data[k]); +// mas[i][j] = 1; +// } +// k += 1; +// } +// } +// for (int i = 0; i < Photo.height; i++) +// { +// for (int j = 0; j < Photo.width; j++) +// { +// printf("%d ", mas[i][j]); +// } +// printf("\n");