#include <iostream>
#include <stack>
using namespace std;
void StackToQueue(void);
int main()
{
StackToQueue();
system("pause");
return 0;
}
//实现stack to queue
void StackToQueue()
{
stack<int> temp1;
stack<int> temp2;
int temp;
while (1)
{
while (1)
{
int data_in;
cin>>data_in;
if (!data_in)
{
break;
}
temp1.push(data_in);
}
while (1)
{
if (temp2.size()==0)
{
while (temp1.size())
{
temp=temp1.top();
temp1.pop();
temp2.push(temp);
}
}
else
{
break;
}
}
cout<<temp2.top();
temp2.pop();
}
}