Сделал 1 Задание со списками
This commit is contained in:
parent
5dbf4901b8
commit
632a718df1
71 changed files with 106 additions and 0 deletions
37
ProcessingSequences/Third/count_max_local.c
Normal file
37
ProcessingSequences/Third/count_max_local.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
#include "count_max_local.h"
|
||||
|
||||
int max(int first, int second) {
|
||||
if (first > second) {
|
||||
return first;
|
||||
}
|
||||
return second;
|
||||
}
|
||||
|
||||
|
||||
int getCountMaxLocal(FILE *file) {
|
||||
int current_n, last, length, maxLen;
|
||||
if (fscanf(file, "%d", ¤t_n) != 1) {
|
||||
printf("File is empty!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
last = current_n;
|
||||
maxLen = EMPTY;
|
||||
length = 1;
|
||||
|
||||
while (fscanf(file, "%d", ¤t_n) == 1) {
|
||||
if (last == current_n) {
|
||||
if (length) length++;
|
||||
} else {
|
||||
if (last > current_n) {
|
||||
maxLen = max(maxLen, length);
|
||||
length = EMPTY;
|
||||
} else {
|
||||
length = 1;
|
||||
}
|
||||
}
|
||||
|
||||
last = current_n;
|
||||
}
|
||||
return max(maxLen, length);
|
||||
}
|
11
ProcessingSequences/Third/count_max_local.h
Normal file
11
ProcessingSequences/Third/count_max_local.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#ifndef COUNT_MAX_LOCAL
|
||||
#define COUNT_MAX_LOCAL
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define EMPTY 0
|
||||
|
||||
int max(int first, int second);
|
||||
int getCountMaxLocal(FILE * file);
|
||||
|
||||
#endif
|
23
ProcessingSequences/Third/get_file.c
Normal file
23
ProcessingSequences/Third/get_file.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include "get_file.h"
|
||||
|
||||
FILE * getFile(void)
|
||||
{
|
||||
FILE * file;
|
||||
char filename[50];
|
||||
|
||||
printf("Enter filename: ");
|
||||
if (scanf("%s", filename) == 1)
|
||||
{
|
||||
file = fopen(filename, "r");
|
||||
if (file == NULL) {
|
||||
printf("Error file!\n");
|
||||
return NULL;
|
||||
} else {
|
||||
return file;
|
||||
}
|
||||
} else
|
||||
{
|
||||
printf("Empty name!\n");
|
||||
return NULL;
|
||||
}
|
||||
}
|
8
ProcessingSequences/Third/get_file.h
Normal file
8
ProcessingSequences/Third/get_file.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef GET_FILE
|
||||
#define GET_FILE
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
FILE * getFile(void);
|
||||
|
||||
#endif
|
18
ProcessingSequences/Third/input.txt
Normal file
18
ProcessingSequences/Third/input.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
1
|
||||
2
|
||||
2
|
||||
2
|
||||
2
|
||||
2
|
||||
1
|
||||
2
|
||||
2
|
||||
2
|
||||
1
|
||||
2
|
||||
2
|
||||
2
|
||||
2
|
||||
2
|
||||
2
|
||||
2
|
13
ProcessingSequences/Third/main.c
Normal file
13
ProcessingSequences/Third/main.c
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include <stdio.h>
|
||||
#include "get_file.h"
|
||||
#include "count_max_local.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
FILE * file = getFile();
|
||||
if (file == NULL) {
|
||||
return -1;
|
||||
}
|
||||
printf("Max length of local maximum is %d", getCountMaxLocal(file));
|
||||
return 0;
|
||||
}
|
11
ProcessingSequences/Third/makefile
Normal file
11
ProcessingSequences/Third/makefile
Normal file
|
@ -0,0 +1,11 @@
|
|||
all: main.o count_max_local.o get_file.o
|
||||
gcc main.o count_max_local.o get_file.o && del *.o
|
||||
|
||||
main.o: main.c
|
||||
gcc -c main.c
|
||||
|
||||
count_max_local.o: count_max_local.c
|
||||
gcc -c count_max_local.c
|
||||
|
||||
get_file.o: get_file.c
|
||||
gcc -c get_file.c
|
Loading…
Add table
Add a link
Reference in a new issue