josiftepe

Untitled

Dec 25th, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     int m,n;
  7.     scanf("%d%d",&n,&m);
  8.     int mat[n][m];
  9.     for(int i=0;i<n;i++)
  10.         for(int j=0;j<m;j++)
  11.         scanf("%d",&mat[i][j]);
  12.     int x,xj;
  13.     scanf("%d%d",&x,&xj);
  14.     if(mat[x][xj]==1){
  15.         for(int i=0;i<n;i++){
  16.             for(int j=0;j<m;j++){
  17.                 printf("%d ", mat[i][j]);
  18.             }
  19.             printf("\n");
  20.         }
  21.     }
  22.         else{
  23.             mat[x][xj] = 1;
  24.             for(int j=xj+1;j<m;j++) // desno od elemenot
  25.             if(mat[x][j]==1){
  26.                 break;
  27.             }
  28.             else{
  29.                 mat[x][j]=1;
  30.             }
  31.             for(int j=xj-1;j>=0;j--) // levo od elementot
  32.             if(mat[x][j]==1){
  33.                 break;
  34.             }
  35.             else{
  36.                 mat[x][j]=1;
  37.             }
  38.             for(int i=x+1;i<n;i++) // dole od elementot
  39.             if(mat[i][xj]==1){
  40.                 break;
  41.             }
  42.             else{
  43.                 mat[i][xj]=1;
  44.             }
  45.             for(int i=x-1;i>=0;i--) // gore od elemento
  46.             if(mat[i][xj]==1){
  47.                 break;
  48.             }
  49.             else{
  50.                 mat[i][xj]=1;
  51.             }
  52.             for(int i=0;i<n;i++){
  53.                 for(int j=0;j<m;j++){
  54.                     printf("%d ", mat[i][j]);
  55.                 }
  56.                 printf("\n");
  57.             }
  58.         }
  59.         }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment