Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*вариант 1
- Дана целочисленная прямоугольная матрица. Определить:
- 1) кол-во строк, не содержащих ни одного нулевого элемента
- 2) максимальное из чисел, встречающихся в заданной матрице более одного раза
- */
- #include <iomanip>
- #include <iostream>
- #include <time.h>
- #include <conio.h>
- #include <cmath>
- #include <memory>
- using namespace std;
- int main() {
- int i, j, m = 0, n = 0, N, M;
- //ДИНАМИЧЕСКИЙ МАССИВ
- /*cout << "size matrix: " << endl;
- cin >> N >> M;
- int** arr = new int*[N];
- for (int i = 0; i < N; i++) {
- arr[i] = new int[M];
- }
- for (int i = 0; i < N; i++) {
- for (int j = 0; j < M; j++) {
- cin >> arr[i][j];
- }
- }
- */
- //СТАТИЧЕСКИЙ МАССИВ
- cout << "size matrix no more 100:" << endl;
- cin >> N >> M;
- int arr[100][100];
- for (int i = 0; i < N; ++i)
- for (int j = 0; j < M; ++j)
- cin >> arr[i][j];
- cout << "\n";
- cout << endl << "original array " << N << "x" << M << ":" << endl;
- for (i = 0; i < N; ++i) {
- for (j = 0; j < M; ++j)
- cout << setw(3) << arr[i][j] << ' ';
- cout << endl;
- }
- int count = 0;
- for (int i = 0; i < N; i++)
- {
- int s = 0;
- for (int j = 0; j < M; j++)
- {
- if (arr[i][j] == 0) s++;
- }
- if (s == 0) count++;
- }
- if (count == 0)
- cout << "matrix hasn't lines without 0" << endl;
- else
- cout << "count lines without 0: " << count << endl;
- int min = -1000;
- for (i = 1; i < N; ++i) {
- for (j = 0; j < M; ++j) {
- if (arr[i][j] < min)
- min = arr[i][j];
- }
- }
- int b[100], s = 0, w, q;
- for (i = 0; i < N; i++){
- for (j = 0; j < M; j++){
- for (q = 0; q < N; q++){
- for (w = 0; w < M; w++){
- if (arr[i][j] == arr[q][w] && (i != q || j != w)){
- b[s] = arr[i][j];
- s++;
- q = N;
- break;
- }
- }
- }
- }
- }
- int max = b[0];
- for (i = 0; i < s; i++)
- {
- if (b[i + 1] > max)
- max = b[i + 1];
- }
- if (max < min)
- cout << endl << "matrix hasn't these max items" << endl;
- else
- cout << endl << "max item more than once: " << max;
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement