Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main(int argc, const char * argv[]) {
- int n, m;
- cin >> n >> m;
- int mat[n][m];
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- cin >> mat[i][j];
- }
- }
- int Z;
- cin >> Z;
- int res_mat[n][m];
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- if(j + Z - 1 < m && i + Z - 1 < n) {
- int zbir = 0;
- for(int k = j; k < j + Z; k++) {
- zbir += mat[i][k];
- zbir += mat[i + Z - 1][k];
- }
- int tmp_i = i + 1;
- for(int k = j + Z - 2; k > j; k--) {
- zbir += mat[tmp_i][k];
- tmp_i++;
- }
- res_mat[i][j] = zbir;
- }
- else {
- res_mat[i][j] = mat[i][j];
- }
- }
- }
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- cout << res_mat[i][j] << " ";
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement