I've been procrastinating for the last time, and I'm going to keep it up today.
Programming Title #: Calculating the sum of the edge elements of a matrix
Source: POJ (Coursera statement: The exercises completed on POJ will not be counted into Coursera's final results. )
Note: Total time limit: 1000ms memory limit: 65536kB description
Enter an integer matrix to compute the sum of elements at the edge of the matrix. The elements of the so-called matrix edges are the elements of the first and last lines and the first and last columns. input
The first behavior integer k, which indicates that there are K-group data.
Each set of data has a multiple-row composition that represents a matrix:
The first row is the number of rows m and the number of columns N (M < 100,n < 100) of the Matrix, separated by a space.
In the next line of M data entered, each row contains n integers, and the integers are separated by spaces.
Output
Outputs the edge element of the corresponding matrix and a row. Sample Input
2
4 4
1 1 1
1 0 0
0 0 1 0 1 0 0 0 0 0 3 3 3 4 1 3 7 1 2 0 1
Sample Output
5
15
Directly paste code:
#include <iostream>
using namespace std;
int main () {
int t;
CIN >> T;
for (int i = 0; i < T; i++) {
int m = 0, n = 0;
CIN >> m >> N;
int shuzu[100][100];//matrix max 100*100
int sum = 0;
for (int j = 0; J < m; J +) {for
(int o = 0; o < n; o++) {
cin >> shuzu[j][o];//Input Array Value
if (j = = 0 | | j = = m-1)//First calculate the first line, the last line
sum + = Shuzu[j][o];
else if (o==0| | o==n-1)//else and then use if to find other than four corners of the first column, the last column
sum + = Shuzu[j][o];
}
cout << sum << endl;
}
return 0;
}