Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdbool.h>
- int main(void) {
- FILE *strmIn = fopen("input.bin", "rb");
- FILE *strmOut = fopen("output.bin", "wb");
- enum {
- lowPyr = -1,
- highPyr = 1,
- notPyr = 0,
- unDef
- } a = unDef;
- int size = 1;
- int *arr = (int *)calloc(size, sizeof(int));
- int i = 0;
- while(fread(&arr[i], sizeof(int), 1, strmIn)) {
- i++;
- if (i == size) {
- size *= 2;
- arr = (int *)realloc(arr, size * sizeof(int));
- }
- }
- size = i;
- for (int i = 0; 2 * i + 1 < size; i++) {
- for (int ii = 1; ii <= 2; ii++) {
- int newI = 2 * i + ii;
- if (newI < size) {
- if (arr[i] > arr[newI]) {
- if (a == unDef) {
- a = lowPyr;
- } else if (a == highPyr) {
- a = notPyr;
- fwrite(&a, sizeof(int), 1, strmOut);
- free(arr);
- return 0;
- }
- } else if (arr[i] < arr[newI]) {
- if (a == unDef) {
- a = highPyr;
- } else if (a == lowPyr) {
- a = notPyr;
- fwrite(&a, sizeof(int), 1, strmOut);
- free(arr);
- return 0;
- }
- }
- }
- }
- }
- if (a == unDef) {
- a = highPyr;
- }
- fwrite(&a, sizeof(int), 1, strmOut);
- free(arr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement