Cod sursa(job #1558660)

Utilizator moise_alexandruMoise Alexandru moise_alexandru Data 29 decembrie 2015 14:31:49
Problema Deque Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.78 kb
#include <iostream>
#include <fstream>
#include <deque>
#include <algorithm>
using namespace std;
ifstream in("carti3.in");
ofstream out("carti3.out");
deque <int> d;

inline void add(int x, int k)
{
    if(k == -1)
        d.push_front(x);
    else
        d.push_back(x);
}
int main()
{
    int n, c;
    in >> n >> c;
    int k = 1;
    for(int i = 1 ; i <= c ; ++ i) {
        int x;
        in >> x;
        d.push_front(x);
    }
    for(int i = 1; i <= n; i++)
    {
        int x;
        in >> x;
        if(x != -1)
            add(x, k);
        else
            k = k * (-1);
    }
    if(k == 1)
        reverse(d.begin(), d.end());
    for(deque<int>::iterator it = d.begin() ; it != d.end() ; ++ it)
        out << *it << '\n';
    return 0;
}