mitakvd

02. Modulated Sum

Sep 27th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int rows;
  10.     int columns;
  11.     int row;
  12.     int sum = 0;
  13.     int modul;
  14.     cin >> columns >> rows;
  15.  
  16.     vector<int> vect;
  17.  
  18.     for(int i = 0; i < columns; ++i)
  19.     {
  20.         for(int j = 0; j < rows; ++j)
  21.         {
  22.             cin >> row;
  23.             vect.push_back(row);
  24.  
  25.         }
  26.  
  27.     }
  28.  
  29.     cin >> modul;
  30.     int counter = 0;
  31.  
  32.     for(int k = 0; k < rows; ++k)
  33.     {
  34.         for(int l = k; l < vect.size(); l+= rows )
  35.         {
  36.             sum += vect[l];
  37.             counter++;
  38.             if(counter == columns)
  39.             {
  40.                 cout << abs(sum % modul) << " ";
  41.                 sum = 0;
  42.                 counter = 0;
  43.             }
  44.         }
  45.  
  46.     }
  47.  
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment