Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. // Листай до "Общая часть для всех 5 задач"
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. double FunctionForTheFifthTask(double***& allArrays, int**& rowsAndColumns) {
  6. double result = 0;
  7. for (int i = 0; i < 3; i++) {
  8. int composition = 1;
  9. for (int j = rowsAndColumns[i][0] - 1; j >= 0; j--)
  10. for (int k = rowsAndColumns[i][1] - 1; k >= rowsAndColumns[i][0] - j; k--)
  11. if (allArrays[i][j][k] > 0)
  12. composition *= allArrays[i][j][k];
  13. result = (i < 2) ? result + composition : result - composition;
  14. }
  15. return result;
  16. }
  17.  
  18. double FunctionForTheFourthTask(double***& allArrays, int**& rowsAndColumns) {
  19. double result = 0;
  20. for (int i = 0; i < 3; i++) {
  21. int composition = 1;
  22. for (int j = 0; j < rowsAndColumns[i][0]; j++)
  23. for (int k = 0; k < rowsAndColumns[i][1] - j - 1; k++)
  24. if (allArrays[i][j][k] > 0)
  25. composition *= allArrays[i][j][k];
  26. result = (i < 2) ? result + composition : result * composition;
  27. }
  28. return result;
  29. }
  30.  
  31. double* FunctionForTheThirdTask(double***& allArrays, int**& rowsAndColumns, int sumOfColumns, int number) {
  32. double* resultArray = new double[sumOfColumns];
  33. int indexOfColumn = 0;
  34. for (int i = 0; i < 3; i++) {
  35. for (int j = 0; j < rowsAndColumns[i][1]; j++) {
  36. int composition = 1;
  37. for (int k = 0; k < rowsAndColumns[i][0]; k++)
  38. composition *= allArrays[i][k][j];
  39. resultArray[indexOfColumn + j] = composition;
  40. }
  41. indexOfColumn += rowsAndColumns[i][1];
  42. }
  43. return resultArray;
  44. }
  45.  
  46. double* FunctionForTheSecondTask(double***& allArrays, int**& rowsAndColumns, int sumOfRows) {
  47. double* resultArray = new double[sumOfRows];
  48. int indexOfRow = 0;
  49. for (int i = 0; i < 3; i++) {
  50. for (int j = 0; j < rowsAndColumns[i][0]; j++) {
  51. int sum = 0;
  52. for (int k = 0; k < rowsAndColumns[i][1]; k++)
  53. sum += allArrays[i][j][k];
  54. resultArray[indexOfRow + j] = sum;
  55. }
  56. indexOfRow += rowsAndColumns[i][0];
  57. }
  58. return resultArray;
  59. }
  60.  
  61. double* FunctionForTheFirstTask(double***& allArrays, int**& rowsAndColumns, int sumOfRows, double number) {
  62. double* resultArray = new double[sumOfRows];
  63. int indexOfRow = 0;
  64. for (int i = 0; i < 3; i++) {
  65. for (int j = 0; j < rowsAndColumns[i][0]; j++) {
  66. int count = 0;
  67. for (int k = 0; k < rowsAndColumns[i][1]; k++)
  68. if (allArrays[i][j][k] > number)
  69. count++;
  70. resultArray[indexOfRow + j] = count;
  71. }
  72. indexOfRow += rowsAndColumns[i][0];
  73. }
  74. return resultArray;
  75. }
  76.  
  77. int main()
  78. {
  79. // Общая часть для всех 5 задач
  80. setlocale(LC_ALL, "russian");
  81. int** rowsAndColumns = new int*[3];
  82. string arrays[3]{ "первого", "второго", "третьего" };
  83. double*** allArrays = new double** [3];
  84. for (int i = 0; i < 3; i++) {
  85. rowsAndColumns[i] = new int[2];
  86. cout << "Введите количество строк для " << arrays[i] << " массива" << endl;
  87. cin >> rowsAndColumns[i][0];
  88. cout << "Введите количество столбцов для " << arrays[i] << " массива" << endl;
  89. cin >> rowsAndColumns[i][1];
  90. double** currentArray = new double* [rowsAndColumns[i][0]];
  91. for (int j = 0; j < rowsAndColumns[i][0]; j++) {
  92. currentArray[j] = new double[rowsAndColumns[i][1]];
  93. cout << "Вводите элементы для " << (j + 1) << " строки" << endl;
  94. for (int k = 0; k < rowsAndColumns[i][1]; k++)
  95. cin >> currentArray[j][k];
  96. }
  97. cout << "Массив сформирован!" << endl;
  98. allArrays[i] = currentArray;
  99. }
  100.  
  101. cout << "-----" << endl;
  102.  
  103. // Теперь индивидуально:
  104.  
  105. // Для 1 задачи
  106. int number1;
  107. cout << "Введите number" << endl;
  108. cin >> number1;
  109. int sumOfRows1 = 0;
  110. for (int i = 0; i < 3; i++)
  111. sumOfRows1 += rowsAndColumns[i][0];
  112. double* result1 = FunctionForTheFirstTask(allArrays, rowsAndColumns, sumOfRows1, number1);
  113. cout << "Результат для 1 задачи: " << endl;
  114. for (int i = 0; i < sumOfRows1; i++)
  115. cout << result1[i] << " ";
  116.  
  117. cout << "\n-----" << endl;
  118.  
  119. // Для 2 задачи
  120. int sumOfRows2 = 0;
  121. for (int i = 0; i < 3; i++)
  122. sumOfRows2 += rowsAndColumns[i][0];
  123. double* result2 = FunctionForTheSecondTask(allArrays, rowsAndColumns, sumOfRows2);
  124. cout << "Результат для 2 задачи: " << endl;
  125. for (int i = 0; i < sumOfRows2; i++)
  126. cout << result2[i] << " ";
  127.  
  128. cout << "\n-----" << endl;
  129.  
  130. // Для 3 задачи
  131. int number3;
  132. cout << "Введите number (В 3 задаче в моем случае никак не используется, так как не совсем ясно, что надо вывести)" << endl;
  133. cin >> number3;
  134. int sumOfColumns3 = 0;
  135. for (int i = 0; i < 3; i++)
  136. sumOfColumns3 += rowsAndColumns[i][0];
  137. double* result3 = FunctionForTheThirdTask(allArrays, rowsAndColumns, sumOfColumns3, number3);
  138. cout << "Результат для 3 задачи: " << endl;
  139. for (int i = 0; i < sumOfColumns3; i++)
  140. cout << result3[i] << " ";
  141.  
  142. cout << "\n-----" << endl;
  143.  
  144. // Для 4 задачи
  145. cout << "Результат для 4 задачи: " << endl;
  146. cout << FunctionForTheFourthTask(allArrays, rowsAndColumns);
  147.  
  148. cout << "\n-----" << endl;
  149.  
  150. // Для 5 задачи
  151. cout << "Результат для 5 задачи: " << endl;
  152. cout << FunctionForTheFifthTask(allArrays, rowsAndColumns);
  153.  
  154. int any;
  155. cin >> any;
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement