Вроде работает
#include <iostream>
using namespace std;
int main()
{
int a;
cin >> a;
int mas[a][a];
for(int i = 0; i<a; i++){
for(int g = 0; g<a; g++){
int t;
cin >> t;
mas[i][g] = t;
}
swap(mas[i][i] , mas[a-i-1][i]);
cout << mas[i][g] << ' ';
cout << endl;
--- Python 3.7 ---
def MatrixRead(Rows, RowLength, ContType):
for row in range(Rows):
print('Enter line ' + str(row))
buff = []
[buff.append(ContType(input())) for _ in range(RowLength)]
yield buff
def MatrixSwap(Matrix, OldPos:tuple, NewPos: tuple):
Matrix[OldPos[0]][OldPos[1]], Matrix[OldPos[1]][OldPos[0]] = Matrix[NewPos[1]][NewPos[0]], Matrix[NewPos[0]][NewPos[1]]
return Matrix
def MatrixPrint(Matrix, end = '\n'):
for Row in Matrix:
print(*Row, end ='\n')
print(end)
def main():
N = int(input()) #Matrix Size
Matr =list( MatrixRead(N, N, int))
MatrixPrint(Matr) #For check
for row in range(N):
for col in range(N):
SecDiagPos = (row, N-col-1)
MainDiagPos = (row, col)
Matr = MatrixSwap(Matr, MainDiagPos, SecDiagPos)
MatrixPrint(Matr)
if __name__ == '__main__':
main()
Объяснение:
Вроде работает
#include <iostream>
using namespace std;
int main()
{
int a;
cin >> a;
int mas[a][a];
for(int i = 0; i<a; i++){
for(int g = 0; g<a; g++){
int t;
cin >> t;
mas[i][g] = t;
}
}
for(int i = 0; i<a; i++){
swap(mas[i][i] , mas[a-i-1][i]);
}
for(int i = 0; i<a; i++){
for(int g = 0; g<a; g++){
cout << mas[i][g] << ' ';
}
cout << endl;
}
}
--- Python 3.7 ---
def MatrixRead(Rows, RowLength, ContType):
for row in range(Rows):
print('Enter line ' + str(row))
buff = []
[buff.append(ContType(input())) for _ in range(RowLength)]
yield buff
def MatrixSwap(Matrix, OldPos:tuple, NewPos: tuple):
Matrix[OldPos[0]][OldPos[1]], Matrix[OldPos[1]][OldPos[0]] = Matrix[NewPos[1]][NewPos[0]], Matrix[NewPos[0]][NewPos[1]]
return Matrix
def MatrixPrint(Matrix, end = '\n'):
for Row in Matrix:
print(*Row, end ='\n')
print(end)
def main():
N = int(input()) #Matrix Size
Matr =list( MatrixRead(N, N, int))
MatrixPrint(Matr) #For check
for row in range(N):
for col in range(N):
SecDiagPos = (row, N-col-1)
MainDiagPos = (row, col)
Matr = MatrixSwap(Matr, MainDiagPos, SecDiagPos)
MatrixPrint(Matr)
if __name__ == '__main__':
main()
Объяснение: