Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- #include <algorithm>
- #include <iomanip>
- #include <cmath>
- #include <list>
- int main()
- {
- std::list<unsigned int> l;
- std::list<int> l1;
- unsigned int value;
- int value1;
- while (std::cin >> value && value && !std::cin.eof()) {
- l.push_back(value);
- }
- while (std::cin >> value1 && !std::cin.eof()) {
- l1.push_back(value1);
- }
- unsigned int first, second, off;
- std::list<int>::iterator it;
- std::list<unsigned int>::iterator it_ins;
- for (it = l1.begin(); it != l1.end(); ) {
- if (*it > 0) {
- first = *it++;
- second = *it++;
- if (first > l.size()) {
- l.push_back(second);
- } else {
- it_ins = l.begin();
- std::advance(it_ins, first - 1);
- l.insert(it_ins, second);
- }
- } else if (*it < 0) {
- off = abs(*it++);
- if (off <= l.size()) {
- it_ins = l.begin();
- std::advance(it_ins, off - 1);
- l.erase(it_ins);
- }
- }
- if (it == l1.end()) {
- break;
- }
- }
- for (it_ins = l.begin(); it_ins != l.end(); ++it_ins) {
- std::cout << *it_ins << std::endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement