Advertisement
Rayzven

Untitled

Feb 10th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. /*Федорчук Антон
  2. Лаба - 8
  3. Вариант-10
  4. Дана целочисленная матрица {Aij}i=1..n,j=1..m (n,m<=100).
  5. Найти столбец, в котором меньше всего чисел, заканчивающихся цифрой 3,
  6. и заменить все элементы матрицы кроме элементов этого столбца числом -17.
  7. */
  8. #include <iostream>
  9.  
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14.     int n, m;
  15.     cin >> n >> m;
  16.     int mas[100][100];
  17.     for(int i = 0; i < n; i++)
  18.         {
  19.         for(int j = 0; j < m; j++)
  20.             cin >> mas[i][j];
  21.         }
  22.  
  23.     int a = 0;
  24.     int min_j = 0;
  25.     int count3 = 0;
  26.     int min3 = INT_MAX;
  27.  
  28.     for(int j = 0; j < m; j++)
  29.     {
  30.         for(int i = 0; i < n; i++)
  31.         {
  32.             if (mas[i][j] % 10 == 3)
  33.                     count3++;
  34.         }
  35.  
  36.         if(count3 < min3)
  37.         {
  38.             min3 = count3;
  39.             min_j = j;
  40.         }
  41.         count3 = 0;
  42.     }
  43.     for(int j = 0; j < m; j++)
  44.     {
  45.         if (j != min_j)
  46.         {
  47.             for(int i = 0; i < n; i++)
  48.                 mas[i][j] = -17;
  49.         }
  50.     }
  51.     for(int i = 0; i < n; i++)
  52.     {
  53.         for(int j = 0; j < m; j++)
  54.         {
  55.             cout << mas[i][j] << " ";
  56.         }
  57.         cout << endl;
  58.     }
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement