0

C++ matrix

An M × N matrix is ​​given. Mirror its elements about the vertical axis of symmetry of the matrix (in this case, the columns with numbers 1 and N, 2 and N - 1, etc. will be swapped).

19th Nov 2020, 9:12 AM
Aidar Ziyadanov
Aidar Ziyadanov - avatar
5 Respostas
0
Where is your attempt?
19th Nov 2020, 9:13 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
i dont know how to do this, this is a task from university. i study remotely...
19th Nov 2020, 9:15 AM
Aidar Ziyadanov
Aidar Ziyadanov - avatar
0
Saying you have 4 numbers for each row. You start the loop with index = 0, so you can access the 1st element of a row with arr[row][index]. What's the mirror of it? arr[row][3], because it's the last element. arr[row][0] <-> arr[row][3] arr[row][1] <-> arr[row][2] You see the pattern? When index is increased by 1, the mirror of it i decreased by 1. When index is increased by N, the mirror of it is decreased by N. Let K be "the length of last element - 1". You can swap arr[row][index] with arr[row][K - index], while iterating the array to half with for(int index = 0 ; index <= K/2 ; index++)
19th Nov 2020, 9:56 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
can you write full program? please)
19th Nov 2020, 10:22 AM
Aidar Ziyadanov
Aidar Ziyadanov - avatar
0
I didn't complete the code. You need to complete it yourself. https://code.sololearn.com/cm0jLLGu0gJ2/?ref=app
19th Nov 2020, 10:50 AM
你知道規則,我也是
你知道規則,我也是 - avatar