From 1e17a5b2c249db90416cf423e532bd686e386fb0 Mon Sep 17 00:00:00 2001 From: AZEN-SGG Date: Tue, 20 May 2025 22:06:06 +0300 Subject: [PATCH] Task 4 and 6-7 are wrong --- 2025.05.23/03Ex/solve.c | 43 +++++++++++----- 2025.05.23/04Ex/solve.c | 54 ++++++++++++++++----- 2025.05.23/dist/Krivoruchenko_SK/solve_03.c | 43 +++++++++++----- 3 files changed, 104 insertions(+), 36 deletions(-) diff --git a/2025.05.23/03Ex/solve.c b/2025.05.23/03Ex/solve.c index 172021e..1d8c39b 100644 --- a/2025.05.23/03Ex/solve.c +++ b/2025.05.23/03Ex/solve.c @@ -5,29 +5,48 @@ int t3_solve (node *head) { - node *next = NULL; + node *last, *next = NULL; int count = 0, local = 0; + if (!head) + return 0; + + last = head; + head = last->next; + if (!head) return 0; for (next = head->next; next; next = head->next) { - int cmp = strcmp(next->string, head->string); - if (cmp < 0) { - if (local) { - count += local; - local = 0; - } - } else if (cmp == 0) { - if (local) - local++; - } else - local = 1; + int cmp_last = strcmp(head->string, last->string); + int cmp_next = strcmp(head->string, next->string); + if (cmp_last > 0) { + local = 1; + } else if (cmp_last == 0) { + if (local) { + if (cmp_next < 0) { + count += local; + local = 0; + } else + local++; + } + } else { + count += local; + local = 0; + } + + last = head; head = next; } + if (strcmp(last->string, head->string) >= 0) + count += local; + else + if (local >= 1) + count += local - 1; + return count; } diff --git a/2025.05.23/04Ex/solve.c b/2025.05.23/04Ex/solve.c index b4a4719..de1056a 100644 --- a/2025.05.23/04Ex/solve.c +++ b/2025.05.23/04Ex/solve.c @@ -5,36 +5,66 @@ int t4_solve (node *head) { + int maximum = 0, count = 0, local = 0, strict = 0; + node *last, *next; + + last = head; + head = last->next; + + for (next = head->next; next; next = head->next) + { + int last_cmp = strcmp(head->string, last->string); + + if (last_cmp == 0) { + local += (local > 0); + } else if (last_cmp < 0) { + if (strict) { + if (maximum < count) + maximum = count; + count = 0; + local = 1; + } else + local += (local > 0); + strict = 0; + } else { + count += local; + local = (local > 0); + + strict = 1; + } + + last = head; + head = next; + } + + return maximum; +} +/* char *last = head->string; - int maximum = 0, count = 0, local = 1, strict = 1; + int maximum = 0, count = 0, local = 0, strict = 0; for (head = head->next; head; head = head->next) { int cmp = strcmp(head->string, last); if (cmp > 0) { count += local; + if (maximum < count) + maximum = count; + count = 0; local = 1; strict = 1; } else if (cmp < 0) { if (!strict) count += local; - if (maximum < count) - maximum = count; - count = 0; local = 1; strict = 0; } else { - local++; + if (local) + local++; } last = head->string; } - if (!strict) - count += local; - - if (maximum < count) - maximum = count; - return maximum; } - +*/ diff --git a/2025.05.23/dist/Krivoruchenko_SK/solve_03.c b/2025.05.23/dist/Krivoruchenko_SK/solve_03.c index 6542931..15ac9d4 100644 --- a/2025.05.23/dist/Krivoruchenko_SK/solve_03.c +++ b/2025.05.23/dist/Krivoruchenko_SK/solve_03.c @@ -5,29 +5,48 @@ int t3_solve (node *head) { - node *next = NULL; + node *last, *next = NULL; int count = 0, local = 0; + if (!head) + return 0; + + last = head; + head = last->next; + if (!head) return 0; for (next = head->next; next; next = head->next) { - int cmp = strcmp(next->string, head->string); - if (cmp < 0) { - if (local) { - count += local; - local = 0; - } - } else if (cmp == 0) { - if (local) - local++; - } else - local = 1; + int cmp_last = strcmp(head->string, last->string); + int cmp_next = strcmp(head->string, next->string); + if (cmp_last > 0) { + local = 1; + } else if (cmp_last == 0) { + if (local) { + if (cmp_next < 0) { + count += local; + local = 0; + } else + local++; + } + } else { + count += local; + local = 0; + } + + last = head; head = next; } + if (strcmp(last->string, head->string) >= 0) + count += local; + else + if (local >= 1) + count += local - 1; + return count; }