Advertisement
frustration

DONE. 1 вариант. двумерный массив. динамический. функции

May 31st, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.22 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. void inp(int N,int M, int ** A){
  18.     for (int i = 0; i < N; ++i)
  19.         for (int j = 0; j < M; ++j)
  20.             scanf_s("%d", &A[i][j]);
  21. }
  22. void out(int N,int M, int ** A){
  23.     for (int i = 0; i < N; ++i) {
  24.         for (int j = 0; j < M; ++j)
  25.             cout << setw(3) << A[i][j] << ' ';
  26.         cout << endl;
  27.     }
  28. }
  29. void colichestvo(int N,int M, int ** A){
  30.     int count = 0;
  31.     for (int i = 0; i < N; i++)
  32.     {
  33.         int s = 0;
  34.         for (int j = 0; j < M; j++)
  35.         {
  36.             if (A[i][j] == 0) s++;
  37.         }
  38.         if (s == 0) count++;
  39.     }
  40.     if (count == 0)
  41.         cout << "matrix hasn't lines without 0" << endl;
  42.     else
  43.         cout << "count lines without 0: " << count << endl;
  44. }
  45. void maximum(int N,int M, int ** A){
  46.     int min = -1000;
  47.     for (int i = 1; i < N; ++i) {
  48.         for (int j = 0; j < M; ++j) {
  49.             if (A[i][j] < min)
  50.                 min = A[i][j];
  51.         }
  52.     }
  53.  
  54.  
  55.     int b[100], s = 0, w, q;
  56.  
  57.     for (int i = 0; i < N; i++){
  58.         for (int j = 0; j < M; j++){
  59.             for (q = 0; q < N; q++){
  60.                 for (w = 0; w < M; w++){
  61.                     if (A[i][j] == A[q][w] && (i != q || j != w)){
  62.                         b[s] = A[i][j];
  63.                         s++;
  64.                         q = N;
  65.                         break;
  66.                     }
  67.                 }
  68.             }
  69.         }
  70.     }
  71.  
  72.  
  73.     int max = b[0];
  74.     for (int i = 0; i < s; i++)
  75.     {
  76.         if (b[i + 1] > max)
  77.             max = b[i + 1];
  78.     }
  79.  
  80.     if (max < min)
  81.         cout << endl << "matrix hasn't these max items" << endl;
  82.     else
  83.         cout << endl << "max item more than once: " << max;
  84. }
  85. int main() {
  86.     int  N, M;
  87.     cout << "size matrix:" << endl;
  88.     cin >> N >> M;
  89.    
  90.     int** A = new int *[N];
  91.     for (int i = 0; i < N; i++)
  92.         A[i] = new int[M];
  93.  
  94.     cout << "enter elements:"<<endl;
  95.     inp(N,M,A);
  96.     cout << "\n";
  97.     cout << endl << "original array " << N << "x" << M << ":" << endl;
  98.     out(N, M, A);
  99.     cout << "\n";
  100.     colichestvo(N, M, A);
  101.     maximum(N, M, A);
  102.     _getch();
  103.  
  104.     return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement