Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <array>
  5. #include <iterator>
  6. #include <time.h>
  7. using namespace std;
  8.  
  9. vector<int> r, s;
  10. auto Generate() -> auto
  11. {
  12.     srand(time(0));
  13.     int **arr = new int*[5];
  14.     for (int i = 0; i < 5; ++i)
  15.         arr[i] = new int[5];
  16.        
  17.     for (int i = 0; i < 5; ++i)
  18.     {
  19.         for (int j = 0; j < 5; ++j)
  20.             arr[i][j] = rand() % 100 < 50 ? 1 : 0;
  21.         arr[i][i] = 0;
  22.     }
  23.  
  24.     return arr;
  25. }
  26.  
  27. auto PrintMatrix(int** arr) ->void
  28. {
  29.     for (int i = 0; i < 5; ++i)
  30.     {
  31.         for (int j = 0; j < 5; ++j)
  32.             cout << arr[i][j] << ' ';
  33.         cout << endl;
  34.     }
  35. }
  36.  
  37. auto foo(int** arr) -> auto
  38. {
  39.     int countr, counts;
  40.     for (int i = 0; i < 5; ++i)
  41.     {
  42.         countr = counts = 0;
  43.         for (int j = 0; j < 5; ++j) {
  44.             if (arr[i][j] && !arr[i][i]) countr++;
  45.             if (!arr[j][i] && arr[i][i]) counts++;
  46.         }
  47.         if (countr == 4) r.push_back(i);
  48.         if (counts == 4) s.push_back(i);
  49.     }
  50. }
  51. int main()
  52. {
  53.     system("chcp 1251");
  54.     system("cls");
  55.     int **matrix = Generate();
  56.     PrintMatrix(matrix);
  57.     foo(matrix);
  58.     if (r.empty() && s.empty()) cerr << "Not found\n" ;
  59.     else {
  60.         cout << "Строки:";    copy(r.begin(), r.end(), ostream_iterator<int>(cout, " "));
  61.         cout << "\nСтолбцы:"; copy(s.begin(), s.end(), ostream_iterator<int>(cout, " "));
  62.     }
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement