Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.90 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int CheckZlavSize(int arr[][9], int size);
  6.  
  7. void main()
  8. {
  9.     int i, j;
  10.     int maxanaf = 0;
  11.     int arr1[9][9];
  12.     int arr2[9][9];
  13.  
  14.  
  15.     //this loolala put random numbers
  16.     for (i = 0; i <= 8; i++)
  17.     {
  18.         for (j = 0; j <= 8; j++)
  19.         {
  20.             arr1[i][j] = 1;
  21.         }
  22.     }
  23.  
  24.     //print arr
  25.  
  26.     for (i = 0; i <= 8; i++)
  27.     {
  28.         for (j = 0; j <= 8; j++)
  29.         {
  30.             cout << arr1[i][j] << " ";
  31.         }
  32.         cout << endl;
  33.     }
  34.  
  35.  
  36.     maxanaf = CheckZlavSize(arr1, 9);
  37.  
  38.     cout <<endl<< maxanaf << endl;
  39.  
  40.     system("pause");
  41. }
  42.  
  43. int CheckZlavSize(int arr[][9], int size)
  44. {
  45.     int i, j, centeri = 0, centerj = 0;
  46.     int maxcounter = 0;
  47.     int counter1 = 0;
  48.     int Uparr[9][9];
  49.     int downarr[9][9];
  50.     int leftarr[9][9];
  51.     int rightarr[9][9];
  52.  
  53.  
  54.     //check the upper + left
  55.     for (i = 0; i < size - 1; i++)
  56.     {
  57.         for (j = 0; j < size - 1; j++)
  58.         {
  59.             if (arr[i][j] == 0) //אם יש אפס זה ישר ישים אפס
  60.             {
  61.                 Uparr[i][j] = 0;
  62.             }
  63.             else
  64.                 if (i == 0) // אם זה שורה ראשונה וכבר בדקנו שזה לא אפס אז זה יכניס 1
  65.                 {
  66.                     Uparr[i][j] = 1;
  67.                 }
  68.                 else
  69.                     Uparr[i][j] = 1 + Uparr[i - 1][j]; //פה המקום הוא בוודאות אחד אז אתה אומר לו לשים 1 ומה שמעליו
  70.         }
  71.     }
  72.  
  73.     //check the down
  74.     for (i = size - 1; i >= 0; i--)
  75.     {
  76.         for (j = size - 1; j >= 0; j--)
  77.         {
  78.             if (arr[i][j] == 0) //אם יש שם אפס אז מכניס אפס
  79.             {
  80.                 downarr[i][j] = 0;
  81.             }
  82.             else
  83.                 if (i == size - 1) // אם אנחנו בשורה האחרונה אז הוא שם אחד כי בדקנו כבר שזה לא אפס
  84.                 {
  85.                     downarr[i][j] = 1;
  86.                 }
  87.                 else
  88.                     downarr[i][j] = 1 + downarr[i + 1][j]; //פה המקום הוא בוודאות אחד אז אתה אומר לו לשים 1 ומה שמתחתיו
  89.         }
  90.     }
  91.  
  92.     //check the left
  93.  
  94.     for (i = 0; i < size - 1; i++)
  95.     {
  96.         for (j = 0; j < size - 1; j++)
  97.         {
  98.             if (arr[i][j] == 0) // אם יש אפס אז תכניס אפס
  99.             {
  100.                 leftarr[i][j] = 0;
  101.             }
  102.             else
  103.                 if (j == 0)  // אם זה העמודה הראשונה וכבר בוודאות זה לא אפס אז תכניס 1
  104.                 {
  105.                     leftarr[i][j] = 1;
  106.                 }
  107.                 else
  108.                     leftarr[i][j] = 1 + leftarr[i][j - 1]; //פה המקום הוא בוודאות אחד אז אתה אומר לו לשים 1 ומה בשמאלו
  109.         }
  110.     }
  111.  
  112.     //check the right
  113.     for (i = size - 1; i >= 0; i--)
  114.     {
  115.         for (j = size - 1; j >= 0; j--)
  116.         {
  117.             if (arr[i][j] == 0) //אם יש שם אפס מכניס אפס
  118.             {
  119.                 rightarr[i][j] = 0;
  120.             }
  121.             else
  122.                 if (j == size - 1) // אם אני בשורה האחרונה אז תכניס אחד כי בדקנו שזה לא אפס
  123.                 {
  124.                     rightarr[i][j] = 1;
  125.                 }
  126.                 else
  127.                     rightarr[i][j] = 1 + rightarr[i][j + 1]; //פה המקום הוא בוודאות אחד אז אתה אומר לו לשים 1 ומה בימינו
  128.         }
  129.     }
  130.     int row = -1;
  131.     int amoada = -1;
  132.     int finamat[9][9];
  133.     int maxmeshutaf = size + 1;
  134.     int maxmaxmeshutaf = 0;
  135.     for (i = 0; i < size - 1; i++)
  136.     {
  137.         for (j = 0; j < size - 1; j++)
  138.         {
  139.             if (Uparr[i][j] <= 1 || leftarr[i][j] <= 1 || rightarr[i][j] <= 1 || downarr[i][j] <= 1)
  140.             {
  141.                 finamat[i][j] == 0;
  142.             }
  143.             else
  144.             {
  145.                 if (Uparr[i][j] <= maxmeshutaf)
  146.                 {
  147.                     maxmeshutaf = Uparr[i][j];
  148.                 }
  149.                 if (downarr[i][j] <= maxmeshutaf)
  150.                 {
  151.                     maxmeshutaf = downarr[i][j];
  152.                 }
  153.                 if (leftarr[i][j] <= maxmeshutaf)
  154.                 {
  155.                     maxmeshutaf = leftarr[i][j];
  156.                 }
  157.                 if (rightarr[i][j] <= maxmeshutaf)
  158.                 {
  159.                     maxmeshutaf = rightarr[i][j];
  160.                 }
  161.                 if (maxmeshutaf < size + 1)
  162.                 {
  163.                     finamat[i][j] = maxmeshutaf;
  164.                     if (maxmeshutaf > maxmaxmeshutaf)
  165.                     {
  166.                         maxmaxmeshutaf = maxmeshutaf;
  167.                         row = i;
  168.                         amoada = j;
  169.                     }
  170.                 }
  171.             }
  172.         }
  173.     }
  174.     if (row > -1 && amoada > -1)
  175.     {
  176.         cout << "The position of the center [" << row << "] " << "[" << amoada << "]";
  177.     }
  178.  
  179.     return maxmaxmeshutaf*2 -1;
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement