PKU 1642 Stacking Cubes

http://poj.org/problem?id=1642
積んである立方体の個数をいろんな方向から見て数えろというような問題。

愚直に数えました。
サンプルが通れば問題ない気がします。

int in[30][30][30];
int p[3];

int get(){
  return in[p[0]][p[1]][p[2]];
}
main(){
  int n;
  while(cin>>n,n){
    memset(in,0,sizeof(in));
    rep(i,n){
      int t;
      int k=0;
      while(cin>>t,t){
        rep(j,t)in[i][k][j]=1;
        ++k;
      }
    }

    rep(rot,2){
      p[0]=p[1]=p[2]=0;
      while(get()){
        while(get()){
          while(get())++p[!rot];
          cout<<p[!rot]<<' ';
          p[!rot]=0;
          ++p[rot<<1];
        }
        cout<<endl;
        p[rot<<1]=0;
        ++p[2-rot];
      }
      cout<<endl;
    }
    cout<<endl;
  }
}