Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main() {
- int n, m;
- scanf("%d%d", &n, &m);
- int mat[n][m];
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- scanf("%d", &mat[i][j]);
- }
- }
- int nova_matrica[(n + 2) / 2][(m + 2) / 2];
- int ni = 0;
- int nj = 0;
- for(int i = 0; i < n; i += 2) {
- nj = 0;
- for(int j = 0; j < m; j += 2) {
- int maks_sosed = mat[i][j];
- if(j + 1 < m) { // deka postoi sosedot koj e na desno od momentalnata kelija
- if(maks_sosed < mat[i][j + 1]) {
- maks_sosed = mat[i][j + 1];
- }
- }
- if(i + 1 < n) {
- if(maks_sosed < mat[i + 1][j]) {
- maks_sosed = mat[i + 1][j];
- }
- }
- if(i + 1 < n && j + 1 < m) {
- if(maks_sosed < mat[i + 1][j + 1]) {
- maks_sosed = mat[i + 1][j + 1];
- }
- }
- nova_matrica[ni][nj] = maks_sosed;
- nj++;
- }
- ni++;
- }
- for(int i = 0; i < ni; i++) {
- for(int j = 0; j < nj; j++) {
- printf("%d ", nova_matrica[i][j]);
- }
- printf("\n");
- }
- }
- /*
- 5 5
- 1 7 5 0 4
- 2 3 18 -3 5
- 14 0 7 5 2
- 3 3 4 5 6
- 7 0 0 1 2
- *.*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement