Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- char** ChangeMatrixsElements(char** matrix, int rows, int cols);
- void DeleteCharMatrix(char** matrix, int rows);
- int main() {
- const int rows = 3;
- const int cols = 3;
- char** inputMatrix = new char* [rows];
- for (int i = 0; i < rows; i++)
- {
- inputMatrix[i] = new char[cols];
- for (int j = 0; j < cols; j++)
- {
- cin >> inputMatrix[i][j];
- }
- cout << "\r\n";
- }
- char** result = ChangeMatrixsElements(inputMatrix, rows, cols);
- for (int row = 0; row < rows; row++)
- {
- for (int col = 0; col < cols; col++)
- {
- cout << result[row][col];
- }
- cout << "\r\n";
- }
- DeleteCharMatrix(inputMatrix, rows);
- DeleteCharMatrix(result, rows);
- }
- char** ChangeMatrixsElements(char** matrix, int rows, int cols) {
- char** tempMatrix = new char* [rows];
- for (int i = 0; i < rows; i++)
- {
- tempMatrix[i] = new char[cols];
- }
- for (int row = 0; row < rows; row++)
- {
- for (int col = 0; col < cols; col++)
- {
- int position = col;
- if (row % 2 == 0 && col % 2 == 0) {
- position = (row + col) % cols;
- }
- else if (row % 2 != 0 && col % 2 != 0) {
- position = (row - col) % cols;
- if (position < 0) {
- position *= -1;
- }
- }
- tempMatrix[row][col] = matrix[row][position];
- }
- }
- return tempMatrix;
- }
- void DeleteCharMatrix(char** matrix, int rows) {
- for (int i = 0; i < rows; i++)
- {
- delete[] matrix[i];
- }
- delete[] matrix;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement