From 1f5d7dc2e213dadd7d0c60902af51730009dd988 Mon Sep 17 00:00:00 2001 From: Egor Starikov Date: Tue, 28 Oct 2025 23:11:54 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=A1=D1=87=D0=B8=D1=82=D0=B0=D0=BB=D0=BE?= =?UTF-8?q?=D1=87=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/iosif.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/iosif.c diff --git a/src/iosif.c b/src/iosif.c new file mode 100644 index 0000000..6c8ea93 --- /dev/null +++ b/src/iosif.c @@ -0,0 +1,58 @@ +#include +#include + +typedef struct Element { + int x; + struct Element* next; +} Element; + +void push(Element* l, int len) { + Element* current = l; + for (int i = 2; i <= len; ++i) { + Element* new_element = (Element*)malloc(sizeof(Element)); + new_element->x = i; + new_element->next = current->next; + current->next = new_element; + current = new_element; + } +} + +int deleting(Element* l, int len, int step) { + Element* current = l; + while (len != 1) { + if (step == 1) { + Element* to_delete = current; + current = current->next; + free(to_delete); + --len; + } else { + for (int i = 1; i < step - 1; ++i) { + current = current->next; + } + Element* to_delete = current->next; + current->next = to_delete->next; + --len; + free(to_delete); + current = current->next; + } + } + int a = current->x; + free(current); + return a; +} + +int main() { + int n, m; + for (n = 1; n <= 10; ++n) { + for (m = 1; m <= 10; ++m) { + Element* mylist = (Element*)malloc(sizeof(Element)); + mylist->x = 1; + mylist->next = mylist; + push(mylist, n); + int ans = deleting(mylist, n, m); + printf("%d ", ans); + } + printf("\n"); + } + return 0; +} From 634c667bd907cc314ab015723f0035b41adb753b Mon Sep 17 00:00:00 2001 From: Egor Starikov Date: Thu, 18 Dec 2025 17:22:22 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/iosif.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/iosif.c b/src/iosif.c index 6c8ea93..15e8053 100644 --- a/src/iosif.c +++ b/src/iosif.c @@ -6,10 +6,14 @@ typedef struct Element { struct Element* next; } Element; -void push(Element* l, int len) { +void push(Element* l, int len) +{ Element* current = l; for (int i = 2; i <= len; ++i) { Element* new_element = (Element*)malloc(sizeof(Element)); + if (new_element == NULL) { + exit(EXIT_FAILURE); + } new_element->x = i; new_element->next = current->next; current->next = new_element; @@ -17,7 +21,8 @@ void push(Element* l, int len) { } } -int deleting(Element* l, int len, int step) { +int deleting(Element* l, int len, int step) +{ Element* current = l; while (len != 1) { if (step == 1) { @@ -38,21 +43,22 @@ int deleting(Element* l, int len, int step) { } int a = current->x; free(current); + current = NULL; return a; } int main() { int n, m; - for (n = 1; n <= 10; ++n) { - for (m = 1; m <= 10; ++m) { - Element* mylist = (Element*)malloc(sizeof(Element)); - mylist->x = 1; - mylist->next = mylist; - push(mylist, n); - int ans = deleting(mylist, n, m); - printf("%d ", ans); - } - printf("\n"); + scanf("%d", &n); + scanf("%d", &m); + Element* mylist = (Element*)malloc(sizeof(Element)); + if (mylist == NULL) { + exit(EXIT_FAILURE); } + mylist->x = 1; + mylist->next = mylist; + push(mylist, n); + int ans = deleting(mylist, n, m); + printf("%d ", ans); return 0; } From 8aa40a6fa27b7b562686592e56400bf1eb7fb1b3 Mon Sep 17 00:00:00 2001 From: Egor Starikov Date: Thu, 18 Dec 2025 17:23:14 +0300 Subject: [PATCH 3/3] webkit --- src/iosif.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/iosif.c b/src/iosif.c index 15e8053..1a0c640 100644 --- a/src/iosif.c +++ b/src/iosif.c @@ -47,7 +47,8 @@ int deleting(Element* l, int len, int step) return a; } -int main() { +int main() +{ int n, m; scanf("%d", &n); scanf("%d", &m);