Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 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 = 0, secondIndex = 0, count = 0;
  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. count += 1;
  33. }
  34. secondIndex = firstIndex + count; //координата-индекс
  35. sumArr[i] = sumOfTen;
  36. *(indexesArr + col * 0 + i) = firstIndex; //indexesArr[i][0] = firstIndex;
  37. *(indexesArr + col * 1 + i) = secondIndex;//indexesArr[i][1] = secondIndex;
  38.  
  39. }
  40. }
  41.  
  42. void searchMaxSum(int sumArr[], int &maxSum, int &point)
  43. {
  44. maxSum = sumArr[0];
  45. for (int element = 1; element < (sizeof(sumArr)/sizeof(sumArr[0])); element++)
  46. {
  47. if (maxSum < sumArr[element])
  48. {
  49. maxSum = sumArr[element];
  50. point = element;
  51. }
  52. }
  53. }
  54.  
  55. void printResult(int &point, int mainArr[], int const arrSize, int maxSum, int *indexesArr, const int row, const int col)
  56. {
  57. cout << "here is the whole array of random numbers: \n";
  58. for (int element = 0; element < arrSize; element++)
  59. {
  60. cout << mainArr[element] << " ";
  61. }
  62. cout << "\n the maximum sum of the 10 segment is " << maxSum;
  63. cout << "\n and the indexes of the beggining and the end are " << *(indexesArr + col * 0 + point) << " and " << *(indexesArr + col * 1 + point);
  64. }
  65.  
  66. int main()
  67. {
  68.  
  69. // приблизительно сколько нужно
  70. int maxSum = 0, point = 0;
  71. int mainArr[arrSize] = {};
  72. int sumArr[sumArrSize] = {};
  73. int indexesArr[row][col] {};
  74.  
  75. fillRandom(mainArr, arrSize);
  76. sumUpSegments(arrSize, mainArr, sumArr, (int*)indexesArr, row, col);
  77. searchMaxSum(sumArr, maxSum, point);
  78. printResult(point, mainArr, arrSize, maxSum, (int*)indexesArr, row, col);
  79.  
  80. cin.get();
  81. cin.get();
  82. return 0;
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement