0013:Switching Railroad Cars
スタックを使う問題。
#include<iostream> #include<stack> using namespace std; int main(void){ int x; stack<int>st; while(cin >> x){ if(x==0 && !st.empty()){ cout << st.top() << endl; st.pop(); } else st.push(x); } return 0; }
スタックを使う問題。
#include<iostream> #include<stack> using namespace std; int main(void){ int x; stack<int>st; while(cin >> x){ if(x==0 && !st.empty()){ cout << st.top() << endl; st.pop(); } else st.push(x); } return 0; }