Aleksandr_Grigoryev

трехдиагональная

Feb 28th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. int main()
  7. {
  8.  
  9.     const int n = 5;
  10.     int mas[n][n] =
  11.     {
  12.         { 1,1,0,0,0 },
  13.         { 1,1,1,0,0 },
  14.         { 0,1,1,0,0 },
  15.         { 0,0,1,1,1 },
  16.         { 0,0,0,1,1 },
  17.     };
  18.     bool q = true;
  19.     bool b = false;
  20.     for (int i = 0; i < n && q; i++)
  21.     {
  22.         for (int j = i + 2; j < n && q; j++)
  23.         {
  24.  
  25.             if (mas[i][j] != 0 || mas[j][i] != 0)
  26.                 q = false;
  27.         }
  28.     }
  29.     if (q) {
  30.         for (int i = 0; i < n - 1 && !b; i++)
  31.         {
  32.             for (int j = i - 1; j <= i + 1 && !b; j++)
  33.             {
  34.                 if (j >= 0 && mas[i][j] != 0)
  35.                 {
  36.                     b = true;
  37.                 }
  38.             }
  39.         }
  40.     }
  41.     if (q && b)  cout << "yes";
  42.     else cout << "not";
  43.     system("pause");
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment