diff --git a/2025.05.23/03Ex/main.c b/2025.05.23/03Ex/main.c index 2d87f26..e094676 100644 --- a/2025.05.23/03Ex/main.c +++ b/2025.05.23/03Ex/main.c @@ -49,7 +49,7 @@ int main (int argc, char *argv[]) } while (0); print_list(head, p); - + t = clock(); res = t3_solve(head); t = (clock() - t) / CLOCKS_PER_SEC; diff --git a/2025.05.23/03Ex/solve.c b/2025.05.23/03Ex/solve.c index acfc958..82af1c8 100644 --- a/2025.05.23/03Ex/solve.c +++ b/2025.05.23/03Ex/solve.c @@ -3,18 +3,30 @@ #include -int t2_solve (node *head) +int t3_solve (node *head) { char *last = head->string; - int count = 1; + int count = 0, local = 1; for (head = head->next; head; head = head->next) { - if (strcmp(head->string, last) > 0) - count++; + int cmp = strcmp(head->string, last); + if (cmp < 0) { + if (local) { + count += local; + local = 0; + } + } else if (cmp == 0) { + if (local) + local++; + } else + local = 1; + last = head->string; } + count += local; + return count; } diff --git a/2025.05.23/03Ex/solve.h b/2025.05.23/03Ex/solve.h index 8cd007e..cbde131 100644 --- a/2025.05.23/03Ex/solve.h +++ b/2025.05.23/03Ex/solve.h @@ -3,6 +3,6 @@ #include "node.h" -int t2_solve (node *head); +int t3_solve (node *head); #endif