Task 3 is done

This commit is contained in:
AZEN-SGG 2025-05-18 21:54:59 +03:00
parent 8f1d1cccff
commit 34f67b3187
3 changed files with 18 additions and 6 deletions

View file

@ -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;

View file

@ -3,18 +3,30 @@
#include <string.h>
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;
}

View file

@ -3,6 +3,6 @@
#include "node.h"
int t2_solve (node *head);
int t3_solve (node *head);
#endif