Task 3 is done
This commit is contained in:
parent
8f1d1cccff
commit
34f67b3187
3 changed files with 18 additions and 6 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
|
||||
#include "node.h"
|
||||
|
||||
int t2_solve (node *head);
|
||||
int t3_solve (node *head);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue