Advertisement
frustration

вариант 1. двумерный массив

Dec 25th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 KB | None | 0 0
  1. /*вариант 1
  2. Дана целочисленная прямоугольная матрица. Определить:
  3. 1) кол-во строк, не содержащих ни одного нулевого элемента
  4. 2) максимальное из чисел, встречающихся в заданной матрице более одного раза
  5. */
  6.  
  7.  
  8. #include <iomanip>
  9. #include <iostream>
  10. #include <time.h>
  11. #include <conio.h>
  12. #include <cmath>
  13. #include <memory>
  14.  
  15. using namespace std;
  16.  
  17. int main() {
  18.     int i, j, m = 0, n = 0, N, M;
  19.  
  20.     //ДИНАМИЧЕСКИЙ МАССИВ
  21.     /*cout << "size matrix: " << endl;
  22.     cin >> N >> M;
  23.  
  24.     int** arr = new int*[N];
  25.  
  26.     for (int i = 0; i < N; i++) {
  27.         arr[i] = new int[M];
  28.     }
  29.  
  30.  
  31.     for (int i = 0; i < N; i++) {
  32.         for (int j = 0; j < M; j++) {
  33.             cin >> arr[i][j];
  34.         }
  35.     }
  36.  
  37. */
  38.  
  39.     //СТАТИЧЕСКИЙ МАССИВ
  40.     cout << "size matrix no more 100:" << endl;
  41.     cin >> N >> M;
  42.     int arr[100][100];
  43.  
  44.     for (int i = 0; i < N; ++i)
  45.         for (int j = 0; j < M; ++j)
  46.             cin >> arr[i][j];
  47.  
  48.     cout << "\n";
  49.    
  50.     cout << endl << "original array " << N << "x" << M << ":" << endl;
  51.  
  52.  
  53.     for (i = 0; i < N; ++i) {
  54.         for (j = 0; j < M; ++j)
  55.             cout << setw(3) << arr[i][j] << ' ';
  56.         cout << endl;
  57.     }
  58.  
  59.     int count = 0;
  60.  
  61.     for (int i = 0; i < N; i++)
  62.     {
  63.         int s = 0;
  64.         for (int j = 0; j < M; j++)
  65.         {
  66.             if (arr[i][j] == 0) s++;
  67.         }
  68.         if (s == 0) count++;
  69.     }
  70.     if (count == 0)
  71.         cout << "matrix hasn't lines without 0" << endl;
  72.     else
  73.     cout << "count lines without 0: " << count << endl;
  74.  
  75.  
  76.     int min = -1000;
  77.     for (i = 1; i < N; ++i) {
  78.         for (j = 0; j < M; ++j) {
  79.             if (arr[i][j] < min)
  80.                 min = arr[i][j];
  81.         }
  82.     }
  83.  
  84.  
  85.     int b[100], s = 0, w, q;
  86.  
  87.     for (i = 0; i < N; i++){
  88.         for (j = 0; j < M; j++){
  89.             for (q = 0; q < N; q++){
  90.                 for (w = 0; w < M; w++){
  91.                     if (arr[i][j] == arr[q][w] && (i != q || j != w)){
  92.                         b[s] = arr[i][j];
  93.                         s++;
  94.                         q = N;
  95.                         break;
  96.                     }
  97.                 }
  98.             }
  99.         }
  100.     }
  101.  
  102.  
  103.     int max = b[0];
  104.     for (i = 0; i < s; i++)
  105.     {
  106.         if (b[i + 1] > max)
  107.             max = b[i + 1];
  108.     }
  109.  
  110.     if (max < min)
  111.         cout << endl << "matrix hasn't these max items" << endl;
  112.     else
  113.         cout << endl << "max item more than once: " << max;
  114.  
  115.     _getch();
  116.  
  117.     return 0;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement