In tryings to solve 3 problem
This commit is contained in:
parent
bccb0a6617
commit
ed505ffc17
33 changed files with 1108 additions and 38 deletions
|
@ -6,7 +6,7 @@
|
|||
int t2_solve (node *head)
|
||||
{
|
||||
char *last = head->string;
|
||||
int count = 1;
|
||||
int count = 0;
|
||||
|
||||
for (head = head->next; head; head = head->next)
|
||||
{
|
||||
|
|
|
@ -5,12 +5,15 @@
|
|||
|
||||
int t3_solve (node *head)
|
||||
{
|
||||
char *last = head->string;
|
||||
int count = 0, local = 1;
|
||||
node *next = NULL;
|
||||
int count = 0, local = 0;
|
||||
|
||||
if (!head)
|
||||
return 0;
|
||||
|
||||
for (head = head->next; head; head = head->next)
|
||||
for (next = head->next; next; next = head->next)
|
||||
{
|
||||
int cmp = strcmp(head->string, last);
|
||||
int cmp = strcmp(next->string, head->string);
|
||||
if (cmp < 0) {
|
||||
if (local) {
|
||||
count += local;
|
||||
|
@ -22,11 +25,9 @@ int t3_solve (node *head)
|
|||
} else
|
||||
local = 1;
|
||||
|
||||
last = head->string;
|
||||
head = next;
|
||||
}
|
||||
|
||||
count += local;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,19 +9,19 @@ node * t9_solve (node *head)
|
|||
{
|
||||
int cmp_last, cmp_next;
|
||||
node *last, *curr, *next,
|
||||
*deleted;
|
||||
last=next=deleted=NULL;
|
||||
*deleted = NULL;
|
||||
cmp_last=cmp_next=0;
|
||||
curr = head;
|
||||
if (!curr)
|
||||
last = head;
|
||||
if (!last)
|
||||
return NULL;
|
||||
curr = last->next;
|
||||
if (!curr)
|
||||
return head;
|
||||
|
||||
for (next = curr->next; next; next = curr->next)
|
||||
{
|
||||
if (deleted)
|
||||
cmp_last = strcmp(curr->string, deleted->string);
|
||||
else if (!last)
|
||||
cmp_last = 1;
|
||||
else
|
||||
cmp_last = strcmp(curr->string, last->string);
|
||||
cmp_next = strcmp(curr->string, next->string); // Как происходит обращение в память для структур?
|
||||
|
@ -31,13 +31,9 @@ node * t9_solve (node *head)
|
|||
if (deleted)
|
||||
delete_node(deleted);
|
||||
deleted = curr;
|
||||
if (last) {
|
||||
last->next = next;
|
||||
curr = last;
|
||||
} else {
|
||||
head = next;
|
||||
curr = NULL;
|
||||
}
|
||||
|
||||
last->next = next;
|
||||
curr = last;
|
||||
} else
|
||||
{
|
||||
if (deleted)
|
||||
|
@ -48,23 +44,6 @@ node * t9_solve (node *head)
|
|||
curr = next;
|
||||
}
|
||||
|
||||
if (deleted)
|
||||
cmp_last = strcmp(curr->string, deleted->string);
|
||||
else if (!last)
|
||||
cmp_last = 1;
|
||||
else
|
||||
cmp_last = strcmp(curr->string, last->string);
|
||||
|
||||
if (cmp_last >= 0)
|
||||
{
|
||||
delete_node(curr);
|
||||
if (last)
|
||||
last->next = NULL;
|
||||
else
|
||||
head = NULL;
|
||||
curr = NULL;
|
||||
}
|
||||
|
||||
if (deleted)
|
||||
delete_node(deleted);
|
||||
|
||||
|
|
67
2025.05.23/dist/Krivoruchenko_SK/main_01.c
vendored
Normal file
67
2025.05.23/dist/Krivoruchenko_SK/main_01.c
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
#include "solve_01.h"
|
||||
#include "node.h"
|
||||
#include "io_node.h"
|
||||
#include "status.h"
|
||||
|
||||
/* ./a01.out p filename */
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
node *head = NULL;
|
||||
char *name;
|
||||
double t;
|
||||
int p, res, task = 1;
|
||||
io_status ret;
|
||||
|
||||
if (
|
||||
!((argc == 3) &&
|
||||
sscanf(argv[1], "%d", &p) == 1 &&
|
||||
argv[2])
|
||||
) {
|
||||
fprintf(stderr, "Usage: %s p filename\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
name = argv[2];
|
||||
|
||||
ret = read_list(&head, name);
|
||||
do {
|
||||
switch (ret) {
|
||||
case SUCCESS:
|
||||
continue;
|
||||
case ERR_OPEN:
|
||||
fprintf (stderr, "%s '%s'!\n", ERR_MSG_OPEN, name);
|
||||
break;
|
||||
case ERR_READ:
|
||||
fprintf (stderr, "%s '%s'!\n", ERR_MSG_READ, name);
|
||||
break;
|
||||
case ERR_MEM:
|
||||
fprintf (stderr, "%s!\n", ERR_MSG_MEM);
|
||||
break;
|
||||
}
|
||||
|
||||
delete_list(head);
|
||||
return -2;
|
||||
} while (0);
|
||||
|
||||
print_list(head, p);
|
||||
|
||||
t = clock();
|
||||
res = t1_solve(head);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
|
||||
delete_list(head);
|
||||
|
||||
if (res < 0) {
|
||||
fprintf (stderr, "%s : Task = %d Undefined error Elapsed = %.2f\n", argv[0], task, t);
|
||||
return -3;
|
||||
} else {
|
||||
fprintf (stdout, "%s : Task = %d Result = %d Elapsed = %.2f\n", argv[0], task, res, t);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
67
2025.05.23/dist/Krivoruchenko_SK/main_02.c
vendored
Normal file
67
2025.05.23/dist/Krivoruchenko_SK/main_02.c
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
#include "solve_02.h"
|
||||
#include "node.h"
|
||||
#include "io_node.h"
|
||||
#include "status.h"
|
||||
|
||||
/* ./a02.out p filename */
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
node *head = NULL;
|
||||
char *name;
|
||||
double t;
|
||||
int p, res, task = 2;
|
||||
io_status ret;
|
||||
|
||||
if (
|
||||
!((argc == 3) &&
|
||||
sscanf(argv[1], "%d", &p) == 1 &&
|
||||
argv[2])
|
||||
) {
|
||||
fprintf(stderr, "Usage: %s p filename\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
name = argv[2];
|
||||
|
||||
ret = read_list(&head, name);
|
||||
do {
|
||||
switch (ret) {
|
||||
case SUCCESS:
|
||||
continue;
|
||||
case ERR_OPEN:
|
||||
fprintf (stderr, "%s '%s'!\n", ERR_MSG_OPEN, name);
|
||||
break;
|
||||
case ERR_READ:
|
||||
fprintf (stderr, "%s '%s'!\n", ERR_MSG_READ, name);
|
||||
break;
|
||||
case ERR_MEM:
|
||||
fprintf (stderr, "%s!\n", ERR_MSG_MEM);
|
||||
break;
|
||||
}
|
||||
|
||||
delete_list(head);
|
||||
return -2;
|
||||
} while (0);
|
||||
|
||||
print_list(head, p);
|
||||
|
||||
t = clock();
|
||||
res = t2_solve(head);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
|
||||
delete_list(head);
|
||||
|
||||
if (res < 0) {
|
||||
fprintf (stderr, "%s : Task = %d Undefined error Elapsed = %.2f\n", argv[0], task, t);
|
||||
return -3;
|
||||
} else {
|
||||
fprintf (stdout, "%s : Task = %d Result = %d Elapsed = %.2f\n", argv[0], task, res, t);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
67
2025.05.23/dist/Krivoruchenko_SK/main_03.c
vendored
Normal file
67
2025.05.23/dist/Krivoruchenko_SK/main_03.c
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
#include "solve_03.h"
|
||||
#include "node.h"
|
||||
#include "io_node.h"
|
||||
#include "status.h"
|
||||
|
||||
/* ./a03.out p filename */
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
node *head = NULL;
|
||||
char *name;
|
||||
double t;
|
||||
int p, res, task = 3;
|
||||
io_status ret;
|
||||
|
||||
if (
|
||||
!((argc == 3) &&
|
||||
sscanf(argv[1], "%d", &p) == 1 &&
|
||||
argv[2])
|
||||
) {
|
||||
fprintf(stderr, "Usage: %s p filename\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
name = argv[2];
|
||||
|
||||
ret = read_list(&head, name);
|
||||
do {
|
||||
switch (ret) {
|
||||
case SUCCESS:
|
||||
continue;
|
||||
case ERR_OPEN:
|
||||
fprintf (stderr, "%s '%s'!\n", ERR_MSG_OPEN, name);
|
||||
break;
|
||||
case ERR_READ:
|
||||
fprintf (stderr, "%s '%s'!\n", ERR_MSG_READ, name);
|
||||
break;
|
||||
case ERR_MEM:
|
||||
fprintf (stderr, "%s!\n", ERR_MSG_MEM);
|
||||
break;
|
||||
}
|
||||
|
||||
delete_list(head);
|
||||
return -2;
|
||||
} while (0);
|
||||
|
||||
print_list(head, p);
|
||||
|
||||
t = clock();
|
||||
res = t3_solve(head);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
|
||||
delete_list(head);
|
||||
|
||||
if (res < 0) {
|
||||
fprintf (stderr, "%s : Task = %d Undefined error Elapsed = %.2f\n", argv[0], task, t);
|
||||
return -3;
|
||||
} else {
|
||||
fprintf (stdout, "%s : Task = %d Result = %d Elapsed = %.2f\n", argv[0], task, res, t);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
67
2025.05.23/dist/Krivoruchenko_SK/main_04.c
vendored
Normal file
67
2025.05.23/dist/Krivoruchenko_SK/main_04.c
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
#include "solve_04.h"
|
||||
#include "node.h"
|
||||
#include "io_node.h"
|
||||
#include "status.h"
|
||||
|
||||
/* ./a04.out p filename */
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
node *head = NULL;
|
||||
char *name;
|
||||
double t;
|
||||
int p, res, task = 4;
|
||||
io_status ret;
|
||||
|
||||
if (
|
||||
!((argc == 3) &&
|
||||
sscanf(argv[1], "%d", &p) == 1 &&
|
||||
argv[2])
|
||||
) {
|
||||
fprintf(stderr, "Usage: %s p filename\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
name = argv[2];
|
||||
|
||||
ret = read_list(&head, name);
|
||||
do {
|
||||
switch (ret) {
|
||||
case SUCCESS:
|
||||
continue;
|
||||
case ERR_OPEN:
|
||||
fprintf (stderr, "%s '%s'!\n", ERR_MSG_OPEN, name);
|
||||
break;
|
||||
case ERR_READ:
|
||||
fprintf (stderr, "%s '%s'!\n", ERR_MSG_READ, name);
|
||||
break;
|
||||
case ERR_MEM:
|
||||
fprintf (stderr, "%s!\n", ERR_MSG_MEM);
|
||||
break;
|
||||
}
|
||||
|
||||
delete_list(head);
|
||||
return -2;
|
||||
} while (0);
|
||||
|
||||
print_list(head, p);
|
||||
|
||||
t = clock();
|
||||
res = t4_solve(head);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
|
||||
delete_list(head);
|
||||
|
||||
if (res < 0) {
|
||||
fprintf (stderr, "%s : Task = %d Undefined error Elapsed = %.2f\n", argv[0], task, t);
|
||||
return -3;
|
||||
} else {
|
||||
fprintf (stdout, "%s : Task = %d Result = %d Elapsed = %.2f\n", argv[0], task, res, t);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
67
2025.05.23/dist/Krivoruchenko_SK/main_05.c
vendored
Normal file
67
2025.05.23/dist/Krivoruchenko_SK/main_05.c
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
#include "solve_05.h"
|
||||
#include "node.h"
|
||||
#include "io_node.h"
|
||||
#include "status.h"
|
||||
|
||||
/* ./a05.out p filename */
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
node *head = NULL;
|
||||
char *name;
|
||||
double t;
|
||||
int p, res, task = 5;
|
||||
io_status ret;
|
||||
|
||||
if (
|
||||
!((argc == 3) &&
|
||||
sscanf(argv[1], "%d", &p) == 1 &&
|
||||
argv[2])
|
||||
) {
|
||||
fprintf(stderr, "Usage: %s p filename\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
name = argv[2];
|
||||
|
||||
ret = read_list(&head, name);
|
||||
do {
|
||||
switch (ret) {
|
||||
case SUCCESS:
|
||||
continue;
|
||||
case ERR_OPEN:
|
||||
fprintf (stderr, "%s '%s'!\n", ERR_MSG_OPEN, name);
|
||||
break;
|
||||
case ERR_READ:
|
||||
fprintf (stderr, "%s '%s'!\n", ERR_MSG_READ, name);
|
||||
break;
|
||||
case ERR_MEM:
|
||||
fprintf (stderr, "%s!\n", ERR_MSG_MEM);
|
||||
break;
|
||||
}
|
||||
|
||||
delete_list(head);
|
||||
return -2;
|
||||
} while (0);
|
||||
|
||||
print_list(head, p);
|
||||
|
||||
t = clock();
|
||||
res = t5_solve(head);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
|
||||
delete_list(head);
|
||||
|
||||
if (res < 0) {
|
||||
fprintf (stderr, "%s : Task = %d Undefined error Elapsed = %.2f\n", argv[0], task, t);
|
||||
return -3;
|
||||
} else {
|
||||
fprintf (stdout, "%s : Task = %d Result = %d Elapsed = %.2f\n", argv[0], task, res, t);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
67
2025.05.23/dist/Krivoruchenko_SK/main_06.c
vendored
Normal file
67
2025.05.23/dist/Krivoruchenko_SK/main_06.c
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
#include "solve_06.h"
|
||||
#include "node.h"
|
||||
#include "io_node.h"
|
||||
#include "status.h"
|
||||
|
||||
/* ./a06.out p filename */
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
node *head = NULL;
|
||||
char *name;
|
||||
double t;
|
||||
int p, res, task = 6;
|
||||
io_status ret;
|
||||
|
||||
if (
|
||||
!((argc == 3) &&
|
||||
sscanf(argv[1], "%d", &p) == 1 &&
|
||||
argv[2])
|
||||
) {
|
||||
fprintf(stderr, "Usage: %s p filename\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
name = argv[2];
|
||||
|
||||
ret = read_list(&head, name);
|
||||
do {
|
||||
switch (ret) {
|
||||
case SUCCESS:
|
||||
continue;
|
||||
case ERR_OPEN:
|
||||
fprintf (stderr, "%s '%s'!\n", ERR_MSG_OPEN, name);
|
||||
break;
|
||||
case ERR_READ:
|
||||
fprintf (stderr, "%s '%s'!\n", ERR_MSG_READ, name);
|
||||
break;
|
||||
case ERR_MEM:
|
||||
fprintf (stderr, "%s!\n", ERR_MSG_MEM);
|
||||
break;
|
||||
}
|
||||
|
||||
delete_list(head);
|
||||
return -2;
|
||||
} while (0);
|
||||
|
||||
print_list(head, p);
|
||||
|
||||
t = clock();
|
||||
res = t6_solve(head);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
|
||||
delete_list(head);
|
||||
|
||||
if (res < 0) {
|
||||
fprintf (stderr, "%s : Task = %d Undefined error Elapsed = %.2f\n", argv[0], task, t);
|
||||
return -3;
|
||||
} else {
|
||||
fprintf (stdout, "%s : Task = %d Result = %d Elapsed = %.2f\n", argv[0], task, res, t);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
67
2025.05.23/dist/Krivoruchenko_SK/main_07.c
vendored
Normal file
67
2025.05.23/dist/Krivoruchenko_SK/main_07.c
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
#include "solve_07.h"
|
||||
#include "node.h"
|
||||
#include "io_node.h"
|
||||
#include "status.h"
|
||||
|
||||
/* ./a07.out p filename */
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
node *head = NULL;
|
||||
char *name;
|
||||
double t;
|
||||
int p, res, task = 7;
|
||||
io_status ret;
|
||||
|
||||
if (
|
||||
!((argc == 3) &&
|
||||
sscanf(argv[1], "%d", &p) == 1 &&
|
||||
argv[2])
|
||||
) {
|
||||
fprintf(stderr, "Usage: %s p filename\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
name = argv[2];
|
||||
|
||||
ret = read_list(&head, name);
|
||||
do {
|
||||
switch (ret) {
|
||||
case SUCCESS:
|
||||
continue;
|
||||
case ERR_OPEN:
|
||||
fprintf (stderr, "%s '%s'!\n", ERR_MSG_OPEN, name);
|
||||
break;
|
||||
case ERR_READ:
|
||||
fprintf (stderr, "%s '%s'!\n", ERR_MSG_READ, name);
|
||||
break;
|
||||
case ERR_MEM:
|
||||
fprintf (stderr, "%s!\n", ERR_MSG_MEM);
|
||||
break;
|
||||
}
|
||||
|
||||
delete_list(head);
|
||||
return -2;
|
||||
} while (0);
|
||||
|
||||
print_list(head, p);
|
||||
|
||||
t = clock();
|
||||
res = t7_solve(head);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
|
||||
delete_list(head);
|
||||
|
||||
if (res < 0) {
|
||||
fprintf (stderr, "%s : Task = %d Undefined error Elapsed = %.2f\n", argv[0], task, t);
|
||||
return -3;
|
||||
} else {
|
||||
fprintf (stdout, "%s : Task = %d Result = %d Elapsed = %.2f\n", argv[0], task, res, t);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
67
2025.05.23/dist/Krivoruchenko_SK/main_08.c
vendored
Normal file
67
2025.05.23/dist/Krivoruchenko_SK/main_08.c
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
#include "solve_08.h"
|
||||
#include "node.h"
|
||||
#include "io_node.h"
|
||||
#include "status.h"
|
||||
|
||||
/* ./a08.out p filename */
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
node *head = NULL;
|
||||
char *name;
|
||||
double t;
|
||||
int p, len, task = 8;
|
||||
io_status ret;
|
||||
|
||||
if (
|
||||
!((argc == 3) &&
|
||||
sscanf(argv[1], "%d", &p) == 1 &&
|
||||
argv[2])
|
||||
) {
|
||||
fprintf(stderr, "Usage: %s p filename\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
name = argv[2];
|
||||
|
||||
ret = read_list(&head, name);
|
||||
do {
|
||||
switch (ret) {
|
||||
case SUCCESS:
|
||||
continue;
|
||||
case ERR_OPEN:
|
||||
fprintf (stderr, "%s '%s'!\n", ERR_MSG_OPEN, name);
|
||||
break;
|
||||
case ERR_READ:
|
||||
fprintf (stderr, "%s '%s'!\n", ERR_MSG_READ, name);
|
||||
break;
|
||||
case ERR_MEM:
|
||||
fprintf (stderr, "%s!\n", ERR_MSG_MEM);
|
||||
break;
|
||||
}
|
||||
|
||||
delete_list(head);
|
||||
return -2;
|
||||
} while (0);
|
||||
|
||||
fprintf (stdout, "Source list:\n");
|
||||
print_list(head, p);
|
||||
|
||||
t = clock();
|
||||
head = t8_solve(head);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
|
||||
fprintf (stdout, "\nFinal list:\n");
|
||||
print_list(head, p);
|
||||
len = get_length(head);
|
||||
|
||||
delete_list(head);
|
||||
|
||||
fprintf (stdout, "%s : Task = %d Length = %d Elapsed = %.2f\n", argv[0], task, len, t);
|
||||
return 0;
|
||||
}
|
||||
|
67
2025.05.23/dist/Krivoruchenko_SK/main_09.c
vendored
Normal file
67
2025.05.23/dist/Krivoruchenko_SK/main_09.c
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
#include "solve_09.h"
|
||||
#include "node.h"
|
||||
#include "io_node.h"
|
||||
#include "status.h"
|
||||
|
||||
/* ./a09.out p filename */
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
node *head = NULL;
|
||||
char *name;
|
||||
double t;
|
||||
int p, len, task = 9;
|
||||
io_status ret;
|
||||
|
||||
if (
|
||||
!((argc == 3) &&
|
||||
sscanf(argv[1], "%d", &p) == 1 &&
|
||||
argv[2])
|
||||
) {
|
||||
fprintf(stderr, "Usage: %s p filename\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
name = argv[2];
|
||||
|
||||
ret = read_list(&head, name);
|
||||
do {
|
||||
switch (ret) {
|
||||
case SUCCESS:
|
||||
continue;
|
||||
case ERR_OPEN:
|
||||
fprintf (stderr, "%s '%s'!\n", ERR_MSG_OPEN, name);
|
||||
break;
|
||||
case ERR_READ:
|
||||
fprintf (stderr, "%s '%s'!\n", ERR_MSG_READ, name);
|
||||
break;
|
||||
case ERR_MEM:
|
||||
fprintf (stderr, "%s!\n", ERR_MSG_MEM);
|
||||
break;
|
||||
}
|
||||
|
||||
delete_list(head);
|
||||
return -2;
|
||||
} while (0);
|
||||
|
||||
fprintf (stdout, "Source list:\n");
|
||||
print_list(head, p);
|
||||
|
||||
t = clock();
|
||||
head = t9_solve(head);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
|
||||
fprintf (stdout, "\nFinal list:\n");
|
||||
print_list(head, p);
|
||||
len = get_length(head);
|
||||
|
||||
delete_list(head);
|
||||
|
||||
fprintf (stdout, "%s : Task = %d Length = %d Elapsed = %.2f\n", argv[0], task, len, t);
|
||||
return 0;
|
||||
}
|
||||
|
67
2025.05.23/dist/Krivoruchenko_SK/main_10.c
vendored
Normal file
67
2025.05.23/dist/Krivoruchenko_SK/main_10.c
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
#include "solve_10.h"
|
||||
#include "node.h"
|
||||
#include "io_node.h"
|
||||
#include "status.h"
|
||||
|
||||
/* ./a10.out p filename */
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
node *head = NULL;
|
||||
char *name;
|
||||
double t;
|
||||
int p, len, task = 10;
|
||||
io_status ret;
|
||||
|
||||
if (
|
||||
!((argc == 3) &&
|
||||
sscanf(argv[1], "%d", &p) == 1 &&
|
||||
argv[2])
|
||||
) {
|
||||
fprintf(stderr, "Usage: %s p filename\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
name = argv[2];
|
||||
|
||||
ret = read_list(&head, name);
|
||||
do {
|
||||
switch (ret) {
|
||||
case SUCCESS:
|
||||
continue;
|
||||
case ERR_OPEN:
|
||||
fprintf (stderr, "%s '%s'!\n", ERR_MSG_OPEN, name);
|
||||
break;
|
||||
case ERR_READ:
|
||||
fprintf (stderr, "%s '%s'!\n", ERR_MSG_READ, name);
|
||||
break;
|
||||
case ERR_MEM:
|
||||
fprintf (stderr, "%s!\n", ERR_MSG_MEM);
|
||||
break;
|
||||
}
|
||||
|
||||
delete_list(head);
|
||||
return -2;
|
||||
} while (0);
|
||||
|
||||
fprintf (stdout, "Source list:\n");
|
||||
print_list(head, p);
|
||||
|
||||
t = clock();
|
||||
head = t10_solve(head);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
|
||||
fprintf (stdout, "\nFinal list:\n");
|
||||
print_list(head, p);
|
||||
len = get_length(head);
|
||||
|
||||
delete_list(head);
|
||||
|
||||
fprintf (stdout, "%s : Task = %d Length = %d Elapsed = %.2f\n", argv[0], task, len, t);
|
||||
return 0;
|
||||
}
|
||||
|
23
2025.05.23/dist/Krivoruchenko_SK/solve_01.c
vendored
Normal file
23
2025.05.23/dist/Krivoruchenko_SK/solve_01.c
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include "solve_01.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int t1_solve (node *head)
|
||||
{
|
||||
char *maximum = head->string;
|
||||
int count = 1;
|
||||
|
||||
for (head = head->next; head; head = head->next)
|
||||
{
|
||||
int cmp = strcmp(head->string, maximum);
|
||||
if (cmp > 0) {
|
||||
maximum = head->string;
|
||||
count = 1;
|
||||
} else if (!cmp)
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
8
2025.05.23/dist/Krivoruchenko_SK/solve_01.h
vendored
Normal file
8
2025.05.23/dist/Krivoruchenko_SK/solve_01.h
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef SOLVE_H
|
||||
#define SOLVE_H
|
||||
|
||||
#include "node.h"
|
||||
|
||||
int t1_solve (node *head);
|
||||
|
||||
#endif
|
20
2025.05.23/dist/Krivoruchenko_SK/solve_02.c
vendored
Normal file
20
2025.05.23/dist/Krivoruchenko_SK/solve_02.c
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include "solve_02.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int t2_solve (node *head)
|
||||
{
|
||||
char *last = head->string;
|
||||
int count = 0;
|
||||
|
||||
for (head = head->next; head; head = head->next)
|
||||
{
|
||||
if (strcmp(head->string, last) > 0)
|
||||
count++;
|
||||
last = head->string;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
8
2025.05.23/dist/Krivoruchenko_SK/solve_02.h
vendored
Normal file
8
2025.05.23/dist/Krivoruchenko_SK/solve_02.h
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef SOLVE_H
|
||||
#define SOLVE_H
|
||||
|
||||
#include "node.h"
|
||||
|
||||
int t2_solve (node *head);
|
||||
|
||||
#endif
|
33
2025.05.23/dist/Krivoruchenko_SK/solve_03.c
vendored
Normal file
33
2025.05.23/dist/Krivoruchenko_SK/solve_03.c
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include "solve_03.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int t3_solve (node *head)
|
||||
{
|
||||
node *next = NULL;
|
||||
int count = 0, local = 0;
|
||||
|
||||
if (!head)
|
||||
return 0;
|
||||
|
||||
for (next = head->next; next; next = head->next)
|
||||
{
|
||||
int cmp = strcmp(next->string, head->string);
|
||||
if (cmp < 0) {
|
||||
if (local) {
|
||||
count += local;
|
||||
local = 0;
|
||||
}
|
||||
} else if (cmp == 0) {
|
||||
if (local)
|
||||
local++;
|
||||
} else
|
||||
local = 1;
|
||||
|
||||
head = next;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
8
2025.05.23/dist/Krivoruchenko_SK/solve_03.h
vendored
Normal file
8
2025.05.23/dist/Krivoruchenko_SK/solve_03.h
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef SOLVE_H
|
||||
#define SOLVE_H
|
||||
|
||||
#include "node.h"
|
||||
|
||||
int t3_solve (node *head);
|
||||
|
||||
#endif
|
40
2025.05.23/dist/Krivoruchenko_SK/solve_04.c
vendored
Normal file
40
2025.05.23/dist/Krivoruchenko_SK/solve_04.c
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
#include "solve_04.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int t4_solve (node *head)
|
||||
{
|
||||
char *last = head->string;
|
||||
int maximum = 0, count = 0, local = 1, strict = 1;
|
||||
|
||||
for (head = head->next; head; head = 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;
|
||||
strict = 0;
|
||||
} else {
|
||||
local++;
|
||||
}
|
||||
last = head->string;
|
||||
}
|
||||
|
||||
if (!strict)
|
||||
count += local;
|
||||
|
||||
if (maximum < count)
|
||||
maximum = count;
|
||||
|
||||
return maximum;
|
||||
}
|
||||
|
8
2025.05.23/dist/Krivoruchenko_SK/solve_04.h
vendored
Normal file
8
2025.05.23/dist/Krivoruchenko_SK/solve_04.h
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef SOLVE_H
|
||||
#define SOLVE_H
|
||||
|
||||
#include "node.h"
|
||||
|
||||
int t4_solve (node *head);
|
||||
|
||||
#endif
|
27
2025.05.23/dist/Krivoruchenko_SK/solve_05.c
vendored
Normal file
27
2025.05.23/dist/Krivoruchenko_SK/solve_05.c
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include "solve_05.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int t5_solve (node *head)
|
||||
{
|
||||
char *last = head->string;
|
||||
int maximum = 1, count = 1;
|
||||
|
||||
for (head = head->next; head; head = head->next)
|
||||
{
|
||||
if (strcmp(head->string, last) > 0)
|
||||
count++;
|
||||
else {
|
||||
if (maximum < count)
|
||||
maximum = count;
|
||||
|
||||
count = 1;
|
||||
}
|
||||
|
||||
last = head->string;
|
||||
}
|
||||
|
||||
return maximum;
|
||||
}
|
||||
|
8
2025.05.23/dist/Krivoruchenko_SK/solve_05.h
vendored
Normal file
8
2025.05.23/dist/Krivoruchenko_SK/solve_05.h
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef SOLVE_H
|
||||
#define SOLVE_H
|
||||
|
||||
#include "node.h"
|
||||
|
||||
int t5_solve (node *head);
|
||||
|
||||
#endif
|
20
2025.05.23/dist/Krivoruchenko_SK/solve_06.c
vendored
Normal file
20
2025.05.23/dist/Krivoruchenko_SK/solve_06.c
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include "solve_06.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int t6_solve (node *head)
|
||||
{
|
||||
char *last = head->string;
|
||||
int count = 1;
|
||||
|
||||
for (head = head->next; head; head = head->next)
|
||||
{
|
||||
if (strcmp(head->string, last))
|
||||
count++;
|
||||
last = head->string;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
8
2025.05.23/dist/Krivoruchenko_SK/solve_06.h
vendored
Normal file
8
2025.05.23/dist/Krivoruchenko_SK/solve_06.h
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef SOLVE_H
|
||||
#define SOLVE_H
|
||||
|
||||
#include "node.h"
|
||||
|
||||
int t6_solve (node *head);
|
||||
|
||||
#endif
|
28
2025.05.23/dist/Krivoruchenko_SK/solve_07.c
vendored
Normal file
28
2025.05.23/dist/Krivoruchenko_SK/solve_07.c
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
#include "solve_07.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int t7_solve (node *head)
|
||||
{
|
||||
char *last = head->string;
|
||||
int maximum = 0, count = 1;
|
||||
|
||||
for (head = head->next; head; head = head->next)
|
||||
{
|
||||
if (strcmp(head->string, last))
|
||||
count++;
|
||||
else {
|
||||
if (maximum < (count-1))
|
||||
maximum = count-1;
|
||||
count = 0;
|
||||
}
|
||||
last = head->string;
|
||||
}
|
||||
|
||||
if (maximum < count)
|
||||
maximum = count;
|
||||
|
||||
return maximum;
|
||||
}
|
||||
|
8
2025.05.23/dist/Krivoruchenko_SK/solve_07.h
vendored
Normal file
8
2025.05.23/dist/Krivoruchenko_SK/solve_07.h
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef SOLVE_H
|
||||
#define SOLVE_H
|
||||
|
||||
#include "node.h"
|
||||
|
||||
int t7_solve (node *head);
|
||||
|
||||
#endif
|
42
2025.05.23/dist/Krivoruchenko_SK/solve_08.c
vendored
Normal file
42
2025.05.23/dist/Krivoruchenko_SK/solve_08.c
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include "solve_08.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
node * t8_solve (node *head)
|
||||
{
|
||||
node *last = head;
|
||||
node *curr, *next;
|
||||
|
||||
curr = head->next;
|
||||
if (!curr)
|
||||
return head;
|
||||
|
||||
while (strcmp(last->string, curr->string) >= 0) {
|
||||
free(last->string);
|
||||
free(last);
|
||||
|
||||
last = curr;
|
||||
head = curr;
|
||||
curr = curr->next;
|
||||
if (!curr)
|
||||
return head;
|
||||
}
|
||||
|
||||
for (next = curr->next; next; next = curr->next)
|
||||
{
|
||||
if (strcmp(curr->string, next->string) >= 0) {
|
||||
free(curr->string);
|
||||
free(curr);
|
||||
|
||||
last->next = next;
|
||||
} else
|
||||
last = curr;
|
||||
|
||||
curr = next;
|
||||
}
|
||||
|
||||
return head;
|
||||
}
|
||||
|
8
2025.05.23/dist/Krivoruchenko_SK/solve_08.h
vendored
Normal file
8
2025.05.23/dist/Krivoruchenko_SK/solve_08.h
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef SOLVE_H
|
||||
#define SOLVE_H
|
||||
|
||||
#include "node.h"
|
||||
|
||||
node * t8_solve (node *head);
|
||||
|
||||
#endif
|
52
2025.05.23/dist/Krivoruchenko_SK/solve_09.c
vendored
Normal file
52
2025.05.23/dist/Krivoruchenko_SK/solve_09.c
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include "solve_09.h"
|
||||
#include "node.h"
|
||||
#include "io_node.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
node * t9_solve (node *head)
|
||||
{
|
||||
int cmp_last, cmp_next;
|
||||
node *last, *curr, *next,
|
||||
*deleted = NULL;
|
||||
cmp_last=cmp_next=0;
|
||||
last = head;
|
||||
if (!last)
|
||||
return NULL;
|
||||
curr = last->next;
|
||||
if (!curr)
|
||||
return head;
|
||||
|
||||
for (next = curr->next; next; next = curr->next)
|
||||
{
|
||||
if (deleted)
|
||||
cmp_last = strcmp(curr->string, deleted->string);
|
||||
else
|
||||
cmp_last = strcmp(curr->string, last->string);
|
||||
cmp_next = strcmp(curr->string, next->string); // Как происходит обращение в память для структур?
|
||||
|
||||
if ((cmp_last >= 0) && (cmp_next >= 0))
|
||||
{
|
||||
if (deleted)
|
||||
delete_node(deleted);
|
||||
deleted = curr;
|
||||
|
||||
last->next = next;
|
||||
curr = last;
|
||||
} else
|
||||
{
|
||||
if (deleted)
|
||||
delete_node(deleted);
|
||||
deleted = NULL;
|
||||
}
|
||||
last = curr;
|
||||
curr = next;
|
||||
}
|
||||
|
||||
if (deleted)
|
||||
delete_node(deleted);
|
||||
|
||||
return head;
|
||||
}
|
||||
|
8
2025.05.23/dist/Krivoruchenko_SK/solve_09.h
vendored
Normal file
8
2025.05.23/dist/Krivoruchenko_SK/solve_09.h
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef SOLVE_H
|
||||
#define SOLVE_H
|
||||
|
||||
#include "node.h"
|
||||
|
||||
node * t9_solve (node *head);
|
||||
|
||||
#endif
|
55
2025.05.23/dist/Krivoruchenko_SK/solve_10.c
vendored
Normal file
55
2025.05.23/dist/Krivoruchenko_SK/solve_10.c
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include "solve_10.h"
|
||||
#include "node.h"
|
||||
#include "io_node.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
node * t10_solve (node *head)
|
||||
{
|
||||
int down = 0;
|
||||
node *last, *curr, *next,
|
||||
*start;
|
||||
last=next=start=NULL;
|
||||
curr = head;
|
||||
|
||||
for (next=curr->next; next; next=curr->next)
|
||||
{
|
||||
if (strcmp(next->string, curr->string) <= 0) {
|
||||
if (!down)
|
||||
start = last;
|
||||
down++;
|
||||
} else {
|
||||
if (down) {
|
||||
if (start) {
|
||||
delete_nodes(start->next, down+1);
|
||||
start->next = next;
|
||||
curr = start;
|
||||
} else {
|
||||
delete_nodes(head, down+1);
|
||||
head = next;
|
||||
curr = NULL;
|
||||
}
|
||||
}
|
||||
down = 0;
|
||||
}
|
||||
|
||||
last = curr;
|
||||
curr = next;
|
||||
}
|
||||
|
||||
if (down) {
|
||||
if (start) {
|
||||
delete_nodes(start->next, down+1);
|
||||
start->next = NULL;
|
||||
} else {
|
||||
delete_nodes(head, down+1);
|
||||
head = NULL;
|
||||
}
|
||||
curr = NULL;
|
||||
last = NULL;
|
||||
}
|
||||
|
||||
return head;
|
||||
}
|
||||
|
8
2025.05.23/dist/Krivoruchenko_SK/solve_10.h
vendored
Normal file
8
2025.05.23/dist/Krivoruchenko_SK/solve_10.h
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef SOLVE_H
|
||||
#define SOLVE_H
|
||||
|
||||
#include "node.h"
|
||||
|
||||
node * t10_solve (node *head);
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue