Сделал задание номер 3 (35)
This commit is contained in:
parent
05ce9de374
commit
f6f440fef3
12 changed files with 138 additions and 0 deletions
9
Second/input.txt
Normal file
9
Second/input.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
123
|
||||
1234
|
||||
12345
|
||||
123456
|
||||
234567
|
||||
345678
|
||||
456789
|
||||
12
|
||||
1
|
8
Second/makefile
Normal file
8
Second/makefile
Normal file
|
@ -0,0 +1,8 @@
|
|||
all: main.o count_func.o
|
||||
gcc main.o count_func.o && del *.o
|
||||
|
||||
main.o: main.c
|
||||
gcc -c main.c
|
||||
|
||||
count_func.o: count_func.c
|
||||
gcc -c count_func.c
|
37
Third/count_max_local.c
Normal file
37
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) {
|
||||
length += 1;
|
||||
} else {
|
||||
if (last > current_n) {
|
||||
maxLen = max(maxLen, length);
|
||||
length = EMPTY;
|
||||
} else {
|
||||
length = 1;
|
||||
}
|
||||
}
|
||||
|
||||
last = current_n;
|
||||
}
|
||||
return max(maxLen, length);
|
||||
}
|
11
Third/count_max_local.h
Normal file
11
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
Third/get_file.c
Normal file
23
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
Third/get_file.h
Normal file
8
Third/get_file.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef GET_FILE
|
||||
#define GET_FILE
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
FILE * getFile(void);
|
||||
|
||||
#endif
|
18
Third/input.txt
Normal file
18
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
Third/main.c
Normal file
13
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
Third/makefile
Normal file
11
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