Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Листай до "Общая часть для всех 5 задач"
- #include <iostream>
- using namespace std;
- double FunctionForTheFifthTask(double***& allArrays, int**& rowsAndColumns) {
- double result = 0;
- for (int i = 0; i < 3; i++) {
- int composition = 1;
- for (int j = rowsAndColumns[i][0] - 1; j >= 0; j--)
- for (int k = rowsAndColumns[i][1] - 1; k >= rowsAndColumns[i][0] - j; k--)
- if (allArrays[i][j][k] > 0)
- composition *= allArrays[i][j][k];
- result = (i < 2) ? result + composition : result - composition;
- }
- return result;
- }
- double FunctionForTheFourthTask(double***& allArrays, int**& rowsAndColumns) {
- double result = 0;
- for (int i = 0; i < 3; i++) {
- int composition = 1;
- for (int j = 0; j < rowsAndColumns[i][0]; j++)
- for (int k = 0; k < rowsAndColumns[i][1] - j - 1; k++)
- if (allArrays[i][j][k] > 0)
- composition *= allArrays[i][j][k];
- result = (i < 2) ? result + composition : result * composition;
- }
- return result;
- }
- double* FunctionForTheThirdTask(double***& allArrays, int**& rowsAndColumns, int sumOfColumns, int number) {
- double* resultArray = new double[sumOfColumns];
- int indexOfColumn = 0;
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < rowsAndColumns[i][1]; j++) {
- int composition = 1;
- for (int k = 0; k < rowsAndColumns[i][0]; k++)
- composition *= allArrays[i][k][j];
- resultArray[indexOfColumn + j] = composition;
- }
- indexOfColumn += rowsAndColumns[i][1];
- }
- return resultArray;
- }
- double* FunctionForTheSecondTask(double***& allArrays, int**& rowsAndColumns, int sumOfRows) {
- double* resultArray = new double[sumOfRows];
- int indexOfRow = 0;
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < rowsAndColumns[i][0]; j++) {
- int sum = 0;
- for (int k = 0; k < rowsAndColumns[i][1]; k++)
- sum += allArrays[i][j][k];
- resultArray[indexOfRow + j] = sum;
- }
- indexOfRow += rowsAndColumns[i][0];
- }
- return resultArray;
- }
- double* FunctionForTheFirstTask(double***& allArrays, int**& rowsAndColumns, int sumOfRows, double number) {
- double* resultArray = new double[sumOfRows];
- int indexOfRow = 0;
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < rowsAndColumns[i][0]; j++) {
- int count = 0;
- for (int k = 0; k < rowsAndColumns[i][1]; k++)
- if (allArrays[i][j][k] > number)
- count++;
- resultArray[indexOfRow + j] = count;
- }
- indexOfRow += rowsAndColumns[i][0];
- }
- return resultArray;
- }
- int main()
- {
- // Общая часть для всех 5 задач
- setlocale(LC_ALL, "russian");
- int** rowsAndColumns = new int*[3];
- string arrays[3]{ "первого", "второго", "третьего" };
- double*** allArrays = new double** [3];
- for (int i = 0; i < 3; i++) {
- rowsAndColumns[i] = new int[2];
- cout << "Введите количество строк для " << arrays[i] << " массива" << endl;
- cin >> rowsAndColumns[i][0];
- cout << "Введите количество столбцов для " << arrays[i] << " массива" << endl;
- cin >> rowsAndColumns[i][1];
- double** currentArray = new double* [rowsAndColumns[i][0]];
- for (int j = 0; j < rowsAndColumns[i][0]; j++) {
- currentArray[j] = new double[rowsAndColumns[i][1]];
- cout << "Вводите элементы для " << (j + 1) << " строки" << endl;
- for (int k = 0; k < rowsAndColumns[i][1]; k++)
- cin >> currentArray[j][k];
- }
- cout << "Массив сформирован!" << endl;
- allArrays[i] = currentArray;
- }
- cout << "-----" << endl;
- // Теперь индивидуально:
- // Для 1 задачи
- int number1;
- cout << "Введите number" << endl;
- cin >> number1;
- int sumOfRows1 = 0;
- for (int i = 0; i < 3; i++)
- sumOfRows1 += rowsAndColumns[i][0];
- double* result1 = FunctionForTheFirstTask(allArrays, rowsAndColumns, sumOfRows1, number1);
- cout << "Результат для 1 задачи: " << endl;
- for (int i = 0; i < sumOfRows1; i++)
- cout << result1[i] << " ";
- cout << "\n-----" << endl;
- // Для 2 задачи
- int sumOfRows2 = 0;
- for (int i = 0; i < 3; i++)
- sumOfRows2 += rowsAndColumns[i][0];
- double* result2 = FunctionForTheSecondTask(allArrays, rowsAndColumns, sumOfRows2);
- cout << "Результат для 2 задачи: " << endl;
- for (int i = 0; i < sumOfRows2; i++)
- cout << result2[i] << " ";
- cout << "\n-----" << endl;
- // Для 3 задачи
- int number3;
- cout << "Введите number (В 3 задаче в моем случае никак не используется, так как не совсем ясно, что надо вывести)" << endl;
- cin >> number3;
- int sumOfColumns3 = 0;
- for (int i = 0; i < 3; i++)
- sumOfColumns3 += rowsAndColumns[i][0];
- double* result3 = FunctionForTheThirdTask(allArrays, rowsAndColumns, sumOfColumns3, number3);
- cout << "Результат для 3 задачи: " << endl;
- for (int i = 0; i < sumOfColumns3; i++)
- cout << result3[i] << " ";
- cout << "\n-----" << endl;
- // Для 4 задачи
- cout << "Результат для 4 задачи: " << endl;
- cout << FunctionForTheFourthTask(allArrays, rowsAndColumns);
- cout << "\n-----" << endl;
- // Для 5 задачи
- cout << "Результат для 5 задачи: " << endl;
- cout << FunctionForTheFifthTask(allArrays, rowsAndColumns);
- int any;
- cin >> any;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement