Last active
February 6, 2025 19:55
-
-
Save Dagor011/150888f4bb119b9ef25a493866b75803 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ConsoleApplication3.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы. | |
// | |
#include <iostream> | |
#include <vector> | |
#include <ctime> | |
int main() { | |
const unsigned short size = 80; | |
const unsigned short max = 12001; | |
const unsigned short min = 128; | |
unsigned short arr[size]{}; | |
unsigned short max_value{ arr[0] }; | |
srand(static_cast<unsigned short>(time(nullptr))); | |
for (unsigned short i = 0; i < size; i++) { | |
bool stat = false; | |
while (!stat) { | |
arr[i] = min + (rand() % (max)); | |
//проверка делимости | |
if ((arr[i] % 3 != 0) && (arr[i] % 8 != 0)) { | |
stat = true; | |
} | |
} | |
//std::cout << arr[i] << std::endl; | |
} | |
for (unsigned short i = 0; i < size; i++) { | |
if (arr[i] > max_value) { | |
max_value = arr[i]; | |
} | |
} | |
std::cout << "max value:" << max_value << std::endl; | |
//правое поддерево | |
std::vector<unsigned short> Rtree = {arr[17]}; | |
for (unsigned short element : arr) { | |
if (element > Rtree.front()) { | |
Rtree.push_back(element); | |
} | |
} | |
for (unsigned short element : Rtree) { | |
std::cout << element << ' '; | |
} | |
//формирование правых ветвей | |
std::cout <<"\n" << "pravie vetvi" << std::endl; | |
std::vector<unsigned short> result; | |
int currentIndex = 0; | |
// | |
result.push_back(Rtree[currentIndex++]); | |
// | |
while (currentIndex < Rtree.size()) | |
{ | |
if (Rtree[currentIndex] > result.back()) | |
{ | |
result.push_back(Rtree[currentIndex]); | |
} | |
currentIndex++; | |
} | |
for (unsigned short element : result) | |
{ | |
std::cout << element << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment