Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <random>
  3. using namespace std;
  4.  
  5. const int arrSize = 150;
  6. const int sumArrSize = 140;
  7. int const row = 160, col = 2;
  8. void fillRandom(int mainArr[], int const arrSize)
  9. {
  10. default_random_engine generator;
  11. uniform_int_distribution<int> distribution(50, 250);
  12.  
  13. for (int element = 0; element < arrSize; element++)
  14. mainArr[element] = distribution(generator);
  15. }
  16.  
  17. //const int row = 100;
  18. //const int col = 12;
  19.  
  20.  
  21. void sumUpSegments(int const arrSize, int mainArr[], int sumArr[], int **indexesArr, const int row, const int col)
  22. {
  23. int temp, firstIndex, secondIndex;
  24. int sumOfTen = 0;
  25. for (int i = 0; i < arrSize; i++)
  26. {
  27. for (int v = 0; v < 10; v++)
  28. {
  29. temp = mainArr[v + i] + mainArr[v + 1 + i];
  30. sumOfTen = sumOfTen + temp;
  31. firstIndex = v + i;
  32. secondIndex = v + 1 + i;
  33. }
  34. sumArr[i] = sumOfTen;
  35. indexesArr[i][0] = firstIndex;
  36. indexesArr[i][1] = secondIndex;
  37. }
  38. }
  39.  
  40. void searchMaxSum(int sumArr[], int &maxSum, int &point)
  41. {
  42. maxSum = sumArr[0];
  43. for (int element = 0; element < (sizeof(sumArr)/sizeof(sumArr[0])); element++)
  44. {
  45. if (maxSum < sumArr[element])
  46. {
  47. maxSum = sumArr[element];
  48. point = element;
  49. }
  50. }
  51. }
  52.  
  53. void printResult(int point, int mainArr[], int const arrSize, int maxSum, int **indexesArr, const int row, const int col)
  54. {
  55. cout << "here is the whole array of random numbers: \n";
  56. for (int element = 0; element < arrSize; element++)
  57. {
  58. cout << mainArr[element] << " ";
  59. }
  60. cout << "\n the maximum sum of the 10 segment is " << maxSum;
  61. cout << "\n and the indexes of the beggining and the end are " << indexesArr[point][0] << " and " << indexesArr[point][1];
  62. }
  63.  
  64. int main()
  65. {
  66.  
  67. // приблизительно сколько нужно
  68. int maxSum = 0, point = 0;
  69. int mainArr[arrSize] = {};
  70. int sumArr[sumArrSize] = {};
  71. int indexesArr[row][col] {};
  72.  
  73. fillRandom(mainArr, arrSize);
  74. sumUpSegments(arrSize, mainArr, sumArr, (int**)indexesArr, row, col);
  75. searchMaxSum(sumArr, maxSum, point);
  76. printResult(point, mainArr, arrSize, maxSum, (int**)indexesArr, row, col);
  77.  
  78. cin.get();
  79. cin.get();
  80. return 0;
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement