mamamaria

2st task (temp)

Feb 7th, 2021 (edited)
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.90 KB | None | 0 0
  1. //На двумерном массиве без ассемблерных вставок
  2. int main()
  3. {
  4.     const int H = 5; const int W = 7; const int h = 3;
  5.     int mas[H][W] = {
  6.         {0, 1, 0, 0, 0, 0, 1},
  7.         {0, 0, 0, 1, 0, 1, 1},
  8.         {0, 1, 0, 1, 0, 1, 1},
  9.         {0, 1, 0, 1, 0, 0, 0},
  10.         {0, 1, 0, 0, 0, 0, 0}
  11.     };
  12.    
  13.     bool checkl=false; int countr = 0; int k; int gcountr = 0;
  14.     for (int j = 0; j < W; j++) {
  15.         for (int i = 0; i < H; ) {
  16.             if ((i != 0)  && (mas[i - 1][j] == 0)) {
  17.                 while(mas[i][j]==1){
  18.                     if (mas[i][j + 1] == 0 && mas[i][j - 1] == 0) {
  19.                         countr++;
  20.                         if (countr > h) {
  21.                             checkl = false; countr = 0; break;
  22.                         }
  23.                         else {
  24.                            
  25.                             checkl = true;
  26.                         }
  27.                     }
  28.                     i++;
  29.                 }
  30.                 if (checkl == true) {
  31.                     if (i-1 == H - 1) {
  32.                         checkl = false;
  33.                         countr = 0;
  34.                         break;
  35.                     }
  36.                     else {
  37.                         gcountr++;
  38.                         countr = 0;
  39.                         checkl = false;
  40.                     }
  41.                 }
  42.             }
  43.            i++;
  44.         }
  45.        
  46.     }
  47.  
  48.     cout << gcountr;
  49.  
  50. }
  51.  
  52. // На одномерном массиве без ассемблерных вставок
  53. int main()
  54. {
  55.     const int H = 5; const int W = 7; const int h = 3;
  56.     int mas[] = {0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1,0, 1, 0, 1, 0, 1, 1,0, 1, 0, 1, 0, 0, 0,0, 1, 0, 0, 0, 0, 0};
  57.    
  58.     bool checkl=false; int countr = 0; int k; int gcountr = 0;
  59.     for (int j = 0; j < W; j++) {
  60.         for (int i = 0; i < H; ) {
  61.             if ((i != 0)  && (mas[(i - 1)*W+j] == 0)) {
  62.                 while(mas[i*W+j]==1){
  63.                     if (mas[i*W+(j + 1)] == 0 && mas[i*W+(j - 1)] == 0) {
  64.                         countr++;
  65.                         if (countr > h) {
  66.                             checkl = false; countr = 0; break;
  67.                         }
  68.                         else {
  69.                            
  70.                             checkl = true;
  71.                         }
  72.                     }
  73.                     i++;
  74.                 }
  75.                 if (checkl == true) {
  76.                     if (i-1 == H - 1) {
  77.                         checkl = false;
  78.                         countr = 0;
  79.                         break;
  80.                     }
  81.                     else {
  82.                         gcountr++;
  83.                         countr = 0;
  84.                         checkl = false;
  85.                     }
  86.                 }
  87.             }
  88.            i++;
  89.         }
  90.        
  91.     }
  92.  
  93.     cout << gcountr;
  94.  
  95. }
Add Comment
Please, Sign In to add comment