--- 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()
Объяснение:
ответ: Pascal последняя версия, задача только на хз почему 1 неправильно
program C1;
var
N, x: int64;
begin
read(x);
read(N);
if (N > 0) and (N <= abs(x)) then
x := x + n
else if (N > 0) and (N >= abs(x)) then
x := x + n + 1;
if (N < 0) and (abs(N) <= abs(x)) then
x := x - abs(N)
else
if (N < 0) and (abs(N) >= abs(x)) then
x := x - abs(N) - 1;
if x <> 0 then
writeln(x)
else begin
if N > x then
x := x +1
x := x -1;
writeln(x);
end;
end.
--- 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()
Объяснение:
ответ: Pascal последняя версия, задача только на хз почему 1 неправильно
program C1;
var
N, x: int64;
begin
read(x);
read(N);
if (N > 0) and (N <= abs(x)) then
x := x + n
else if (N > 0) and (N >= abs(x)) then
x := x + n + 1;
if (N < 0) and (abs(N) <= abs(x)) then
x := x - abs(N)
else
if (N < 0) and (abs(N) >= abs(x)) then
x := x - abs(N) - 1;
if x <> 0 then
writeln(x)
else begin
if N > x then
x := x +1
else
x := x -1;
writeln(x);
end;
end.
Объяснение: