From 6f21fa116f4bec322a183a66b53a5d71352b0324 Mon Sep 17 00:00:00 2001 From: AZEN-SGG Date: Tue, 20 May 2025 23:03:18 +0300 Subject: [PATCH] Task 4 is done --- 2025.05.23/04Ex/solve.c | 36 +++---------- 2025.05.23/dist/Krivoruchenko_SK/solve_04.c | 56 ++++++++++++--------- 2 files changed, 39 insertions(+), 53 deletions(-) diff --git a/2025.05.23/04Ex/solve.c b/2025.05.23/04Ex/solve.c index de1056a..d751de4 100644 --- a/2025.05.23/04Ex/solve.c +++ b/2025.05.23/04Ex/solve.c @@ -16,7 +16,13 @@ int t4_solve (node *head) int last_cmp = strcmp(head->string, last->string); if (last_cmp == 0) { - local += (local > 0); + if (strict) { + if (maximum < count) + maximum = count; + count = 0; + local = 1; + } else + local += (local > 0); } else if (last_cmp < 0) { if (strict) { if (maximum < count) @@ -39,32 +45,4 @@ int t4_solve (node *head) return maximum; } -/* - char *last = head->string; - 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; - local = 1; - strict = 0; - } else { - if (local) - local++; - } - last = head->string; - } - - return maximum; -} -*/ diff --git a/2025.05.23/dist/Krivoruchenko_SK/solve_04.c b/2025.05.23/dist/Krivoruchenko_SK/solve_04.c index 5e65862..90a0db6 100644 --- a/2025.05.23/dist/Krivoruchenko_SK/solve_04.c +++ b/2025.05.23/dist/Krivoruchenko_SK/solve_04.c @@ -5,35 +5,43 @@ int t4_solve (node *head) { - char *last = head->string; - int maximum = 0, count = 0, local = 1, strict = 1; + int maximum = 0, count = 0, local = 0, strict = 0; + node *last, *next; - for (head = head->next; head; head = head->next) + last = head; + head = last->next; + + for (next = head->next; next; next = head->next) { - int cmp = strcmp(head->string, last); - if (cmp > 0) { - count += local; - local = 1; - strict = 1; - } else if (cmp < 0) { - if (!strict) - count += local; - if (maximum < count) - maximum = count; - count = 0; - local = 1; + int last_cmp = strcmp(head->string, last->string); + + if (last_cmp == 0) { + if (strict) { + if (maximum < count) + maximum = count; + count = 0; + local = 1; + } else + 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 { - local++; - } - last = head->string; - } - - if (!strict) - count += local; + count += local; + local = (local > 0); - if (maximum < count) - maximum = count; + strict = 1; + } + + last = head; + head = next; + } return maximum; }