← 返回 capitalone 的题目列表Sum Elements at Indices Divisible by 3 in Spiral Matrix
类型:online_judge
capitalone
Given a n x n matrix, flatten it in spiral order and return the sum of elements with index%3 == 0.
Input format:
n: dimension of the matrix.
matrix: an n x n matrix consisting of integers.
Output format:
An integer representing the sum of elements at index%3 == 0.
Example:
Input:
3
1 2 3
4 5 6
7 8 9
Output: 12
Explanation: The spiral flatten matrix sequence is 1, 2, 3, 6, 9, 8, 7, 4, 5, where elements at indices 0, 3, 6 are 1, 6, 5 respectively, summing up to 12.
Example
Input
3
1 2 3
4 5 6
7 8 9