らての精進日記

修行をします

aoj0013:Switching Railroad Cars

解法

どう見てもスタックなのでスタック(のようなもの)を適当に作るなりする。

コード

#include<bits/stdc++.h>
using namespace std;

int s[10],t;

int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        if(n)s[t++]=n;
        else printf("%d\n",s[--t]);
    }
    return 0;
}