Advertisement
Vladislav_Bezruk

ITEMS REMAINED

Jul 9th, 2022
690
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. //ITEMS REMAINED
  2.  
  3. #include <iostream>
  4.  
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     int x;
  12.  
  13.     //sequence A
  14.     vector<int> a;
  15.  
  16.     //sequence B
  17.     vector<int> b;
  18.  
  19.     vector<int> c;
  20.  
  21.     //reading sequence A
  22.     while (cin >> x && x != -1)
  23.     {
  24.         a.push_back(x);
  25.     }
  26.  
  27.     //reading sequence B
  28.     while (cin >> x && x != -1)
  29.     {
  30.         b.push_back(x);
  31.     }
  32.  
  33.     for (int x : b)
  34.     {
  35.         for (int i = 0; i < a.size(); i++)
  36.         {
  37.             //add a[i] to C if a[i] isn't divisible by b[i]
  38.             if (i % x != 0)
  39.             {
  40.                 c.push_back(a[i]);
  41.             }
  42.         }
  43.  
  44.         //we leave the rest of the elements in A
  45.         a = c;
  46.  
  47.         c.clear();
  48.     }
  49.  
  50.     //print the sequence A
  51.     for (int x : a)
  52.     {
  53.         cout << x << " ";
  54.     }
  55.  
  56.     cout << "-1";
  57.  
  58.     return 0;
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement