Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <array>
- #include <iterator>
- #include <time.h>
- using namespace std;
- vector<int> r, s;
- auto Generate() -> auto
- {
- srand(time(0));
- int **arr = new int*[5];
- for (int i = 0; i < 5; ++i)
- arr[i] = new int[5];
- for (int i = 0; i < 5; ++i)
- {
- for (int j = 0; j < 5; ++j)
- arr[i][j] = rand() % 100 < 50 ? 1 : 0;
- arr[i][i] = 0;
- }
- return arr;
- }
- auto PrintMatrix(int** arr) ->void
- {
- for (int i = 0; i < 5; ++i)
- {
- for (int j = 0; j < 5; ++j)
- cout << arr[i][j] << ' ';
- cout << endl;
- }
- }
- auto foo(int** arr) -> auto
- {
- int countr, counts;
- for (int i = 0; i < 5; ++i)
- {
- countr = counts = 0;
- for (int j = 0; j < 5; ++j) {
- if (arr[i][j] && !arr[i][i]) countr++;
- if (!arr[j][i] && arr[i][i]) counts++;
- }
- if (countr == 4) r.push_back(i);
- if (counts == 4) s.push_back(i);
- }
- }
- int main()
- {
- system("chcp 1251");
- system("cls");
- int **matrix = Generate();
- PrintMatrix(matrix);
- foo(matrix);
- if (r.empty() && s.empty()) cerr << "Not found\n" ;
- else {
- cout << "Строки:"; copy(r.begin(), r.end(), ostream_iterator<int>(cout, " "));
- cout << "\nСтолбцы:"; copy(s.begin(), s.end(), ostream_iterator<int>(cout, " "));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement