Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
1.4 kB
2
Indexable
Never
// Файл header.h

#include <iostream>
using namespace std;

#define FIND_MINIMUM_ELEMENT(arr, size, min_index) \
    { \
        min_index = 0; \
        for (int i = 1; i < size; ++i) { \
            if (arr[i] < arr[min_index]) { \
                min_index = i; \
            } \
        } \
    }

#define SUM_BETWEEN_NEGATIVES(arr, size, sum) \
    { \
        int first_negative = -1, second_negative = -1; \
        for (int i = 0; i < size; ++i) { \
            if (arr[i] < 0) { \
                if (first_negative == -1) { \
                    first_negative = i; \
                } else if (second_negative == -1) { \
                    second_negative = i; \
                } else { \
                    first_negative = second_negative; \
                    second_negative = i; \
                } \
            } \
        } \
        sum = 0; \
        if (second_negative != -1) { \
            for (int i = first_negative + 1; i < second_negative; ++i) { \
                sum += arr[i]; \
            } \
        } \
    }

#define CONVERT_ARRAY(arr, size) \
    { \
        int write_index = 0; \
        for (int i = 0; i < size; ++i) { \
            if (arr[i] < 0 && arr[i] >= -1) { \
                swap(arr[write_index++], arr[i]); \
            } \
        } \
    }