I Got a Matrix! [Simulation]

Description–

Given an n * m matrix A, interrogation of the matrix and the elements of the edge. The edge of the so-called matrix elements, is the first line and
the elements as well as elements of the last line of the first column and the last column.


Input–

The first line contains two integers n and m.
After n lines each containing m integers Ai, j.

Output–

Total line contains an integer ans, the edge of the matrix elements represents the sum.


Sample Input–

3 3
3 4 1
3 7 1
2 0 1

Sample Output–

15


Notes -

To 100% of the data: n, m ≤ 100


Code -

#include<iostream>
#include<cstdio>
using namespace std;
int n,m,a[105][105];
long long ans;
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i)
	  for (int j=1;j<=m;++j)
	  {
	  	  scanf("%d",&a[i][j]);
	  	  if (i==1 || i==n || j==1 || j==m) ans+=a[i][j];
	  }
	printf("%lld",ans); 
	
	return 0;
} 

Guess you like

Origin blog.csdn.net/qq_43654542/article/details/90698728
got