Task 4 is done
This commit is contained in:
parent
1e17a5b2c2
commit
6f21fa116f
2 changed files with 39 additions and 53 deletions
|
@ -16,7 +16,13 @@ int t4_solve (node *head)
|
||||||
int last_cmp = strcmp(head->string, last->string);
|
int last_cmp = strcmp(head->string, last->string);
|
||||||
|
|
||||||
if (last_cmp == 0) {
|
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) {
|
} else if (last_cmp < 0) {
|
||||||
if (strict) {
|
if (strict) {
|
||||||
if (maximum < count)
|
if (maximum < count)
|
||||||
|
@ -39,32 +45,4 @@ int t4_solve (node *head)
|
||||||
|
|
||||||
return maximum;
|
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;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
54
2025.05.23/dist/Krivoruchenko_SK/solve_04.c
vendored
54
2025.05.23/dist/Krivoruchenko_SK/solve_04.c
vendored
|
@ -5,36 +5,44 @@
|
||||||
|
|
||||||
int t4_solve (node *head)
|
int t4_solve (node *head)
|
||||||
{
|
{
|
||||||
char *last = head->string;
|
int maximum = 0, count = 0, local = 0, strict = 0;
|
||||||
int maximum = 0, count = 0, local = 1, strict = 1;
|
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);
|
int last_cmp = strcmp(head->string, last->string);
|
||||||
if (cmp > 0) {
|
|
||||||
count += local;
|
if (last_cmp == 0) {
|
||||||
local = 1;
|
if (strict) {
|
||||||
strict = 1;
|
if (maximum < count)
|
||||||
} else if (cmp < 0) {
|
maximum = count;
|
||||||
if (!strict)
|
count = 0;
|
||||||
count += local;
|
local = 1;
|
||||||
if (maximum < count)
|
} else
|
||||||
maximum = count;
|
local += (local > 0);
|
||||||
count = 0;
|
} else if (last_cmp < 0) {
|
||||||
local = 1;
|
if (strict) {
|
||||||
|
if (maximum < count)
|
||||||
|
maximum = count;
|
||||||
|
count = 0;
|
||||||
|
local = 1;
|
||||||
|
} else
|
||||||
|
local += (local > 0);
|
||||||
strict = 0;
|
strict = 0;
|
||||||
} else {
|
} else {
|
||||||
local++;
|
count += local;
|
||||||
|
local = (local > 0);
|
||||||
|
|
||||||
|
strict = 1;
|
||||||
}
|
}
|
||||||
last = head->string;
|
|
||||||
|
last = head;
|
||||||
|
head = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strict)
|
|
||||||
count += local;
|
|
||||||
|
|
||||||
if (maximum < count)
|
|
||||||
maximum = count;
|
|
||||||
|
|
||||||
return maximum;
|
return maximum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue