Advertisement
vaziliybober

Untitled

Oct 14th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7.   const int n = 2;
  8.   const int m = 3;
  9.  
  10.   int** a = new int*[n];
  11.   int nStrings = 0;
  12.  
  13.   for (int i = 0; i < n; i++) {
  14.     bool noZeros = true;
  15.     a[i] = new int[m];
  16.  
  17.     for (int j = 0; j < m; j++) {
  18.       cin >> a[i][j];
  19.  
  20.       if (a[i][j] == 0) {
  21.         noZeros = false;
  22.       }
  23.     }
  24.  
  25.     if (noZeros == true) {
  26.       nStrings++;
  27.  
  28.       for (int j = 0; j < m; j++) {
  29.         a[i][j] = 3;
  30.       }
  31.     }
  32.   }
  33.  
  34.   cout << "Исходный массив: \n";
  35.   for (int i = 0; i < n; i++) {
  36.  
  37.     for (int j = 0; j < m; j++) {
  38.       cout << a[i][j] << " ";
  39.     }
  40.  
  41.     cout << "\n";
  42.   }
  43.  
  44.   cout << "Преобразованный массив: \n";
  45.   for (int i = 0; i < n; i++) {
  46.  
  47.     for (int j = 0; j < m; j++) {
  48.       cout << a[i][j] << " ";
  49.     }
  50.  
  51.     cout << "\n";
  52.   }
  53.  
  54.   cout << "Количество строк без нулей: " << nStrings;
  55.   return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement