Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #!/bin/python
  2.  
  3. """
  4. Input Format:
  5. The first line contains a single integer. The next lines denote the matrix's rows, with each line containing space-separated integers describing the columns.
  6.  
  7. Output Format
  8. Print the absolute difference between the two sums of the matrix's diagonals as a single integer.
  9.  
  10. Sample Input
  11. 3
  12. 11 2 4
  13. 4 5 6
  14. 10 8 -12
  15.  
  16. Sample Output
  17. 15
  18.  
  19. Explanation
  20.  
  21. The primary diagonal is:
  22. 11
  23. 5
  24. -12
  25.  
  26. Sum across the primary diagonal: 11 + 5 - 12 = 4
  27.  
  28. The secondary diagonal is:
  29. 4
  30. 5
  31. 10
  32. Sum across the secondary diagonal: 4 + 5 + 10 = 19
  33. Difference: |4 - 19| = 15
  34. """
  35.  
  36. import sys
  37.  
  38. n = int(raw_input().strip())
  39. a = []
  40. for a_i in xrange(n):
  41. a_temp = map(int,raw_input().strip().split(' '))
  42. a.append(a_temp)
  43.  
  44. print abs(sum([(a[i][n-i-1] - a[i][i]) for i in range(n)]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement