Advertisement
wowonline

Untitled

Mar 19th, 2022
1,011
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <iomanip>
  5. #include <cmath>
  6. #include <list>
  7.  
  8.  
  9. int main()
  10. {
  11.     std::list<unsigned int> l;
  12.     std::list<int> l1;
  13.     unsigned int value;
  14.     int value1;
  15.  
  16.     while (std::cin >> value && value && !std::cin.eof()) {
  17.         l.push_back(value);
  18.     }
  19.  
  20.     while (std::cin >> value1 && !std::cin.eof()) {
  21.         l1.push_back(value1);
  22.     }
  23.  
  24.     unsigned int first, second, off;
  25.     std::list<int>::iterator it;
  26.     std::list<unsigned int>::iterator it_ins;
  27.     for (it = l1.begin(); it != l1.end(); ) {
  28.         if (*it > 0) {
  29.             first = *it++;
  30.             second = *it++;
  31.             if (first > l.size()) {
  32.                 l.push_back(second);
  33.             } else {
  34.                 it_ins = l.begin();
  35.                 std::advance(it_ins, first - 1);
  36.                 l.insert(it_ins, second);
  37.             }
  38.         } else if (*it < 0) {
  39.             off = abs(*it++);
  40.             if (off <= l.size()) {
  41.                 it_ins = l.begin();
  42.                 std::advance(it_ins, off - 1);
  43.                 l.erase(it_ins);
  44.             }
  45.         }
  46.         if (it == l1.end()) {
  47.             break;
  48.         }
  49.     }
  50.  
  51.     for (it_ins = l.begin(); it_ins != l.end(); ++it_ins) {
  52.         std::cout << *it_ins << std::endl;
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement