迴圈
輸入n m
建立二維指標陣列
輸入陣列
迴圈
輸入範圍
相加後輸出
刪除指標
#include<iostream>
using namespace std;
int main()
{
int n, m;
int x1, y1, x2, y2;
int ans;
while(cin >> n>> m)
{
int **food = new int*[n+1];
for(int i = 1; i<=n; i++)
food[i] = new int[n+1];
for(int i = 1; i<=n; i++)
for(int j = 1; j<=n; j++)
cin >> food[i][j];
while(m--)
{
cin >> x1 >> y1 >> x2 >> y2;
ans = 0;
for(int i = x1; i<=x2; i++)
for(int j = y1; j<=y2; j++)
ans += food[i][j];
cout << ans << endl;
}
delete [] food;
}
return 0;
}
留言列表