Given a square matrix of size , calculate the absolute difference
between the sums of its diagonals. input is like 1st line matriz size,
other lines are matrix lines of ints separated by spaces
基于上述陈述,可以实现如下目标:
import sys
arraySize = int(raw_input().strip())
array = []
for i in range(arraySize):
temp = list(map(int,raw_input().strip().split(' ')))
array.append(temp)
PrimaryDiagonalSum=0
SecondaryDiagonalSum=0
for i in range(arraySize):
for j in range(arraySize):
if i==j:
PrimaryDiagonalSum+=array[i][j]
if (arraySize-1)-i==j:
SecondaryDiagonalSum+=array[i][j]
print(abs(PrimaryDiagonalSum-SecondaryDiagonalSum))
问题陈述:
基于上述陈述,可以实现如下目标:
样本输入:
^{pr2}$样本输出:
您可以在一次迭代中完成(即不需要j)
相关问题 更多 >
编程相关推荐