Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <random>
- using namespace std;
- const int arrSize = 150;
- const int sumArrSize = 140;
- int const row = 160, col = 2;
- void fillRandom(int mainArr[], int const arrSize)
- {
- default_random_engine generator;
- uniform_int_distribution<int> distribution(50, 250);
- for (int element = 0; element < arrSize; element++)
- mainArr[element] = distribution(generator);
- }
- //const int row = 100;
- //const int col = 12;
- void sumUpSegments(int const arrSize, int mainArr[], int sumArr[], int **indexesArr, const int row, const int col)
- {
- int temp, firstIndex, secondIndex;
- int sumOfTen = 0;
- for (int i = 0; i < arrSize; i++)
- {
- for (int v = 0; v < 10; v++)
- {
- temp = mainArr[v + i] + mainArr[v + 1 + i];
- sumOfTen = sumOfTen + temp;
- firstIndex = v + i;
- secondIndex = v + 1 + i;
- }
- sumArr[i] = sumOfTen;
- indexesArr[i][0] = firstIndex;
- indexesArr[i][1] = secondIndex;
- }
- }
- void searchMaxSum(int sumArr[], int &maxSum, int &point)
- {
- maxSum = sumArr[0];
- for (int element = 0; element < (sizeof(sumArr)/sizeof(sumArr[0])); element++)
- {
- if (maxSum < sumArr[element])
- {
- maxSum = sumArr[element];
- point = element;
- }
- }
- }
- void printResult(int point, int mainArr[], int const arrSize, int maxSum, int **indexesArr, const int row, const int col)
- {
- cout << "here is the whole array of random numbers: \n";
- for (int element = 0; element < arrSize; element++)
- {
- cout << mainArr[element] << " ";
- }
- cout << "\n the maximum sum of the 10 segment is " << maxSum;
- cout << "\n and the indexes of the beggining and the end are " << indexesArr[point][0] << " and " << indexesArr[point][1];
- }
- int main()
- {
- // приблизительно сколько нужно
- int maxSum = 0, point = 0;
- int mainArr[arrSize] = {};
- int sumArr[sumArrSize] = {};
- int indexesArr[row][col] {};
- fillRandom(mainArr, arrSize);
- sumUpSegments(arrSize, mainArr, sumArr, (int**)indexesArr, row, col);
- searchMaxSum(sumArr, maxSum, point);
- printResult(point, mainArr, arrSize, maxSum, (int**)indexesArr, row, col);
- cin.get();
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement