#include<iostream>
#define N 10000
using namespace std;
struct stack{
int stackarray[N];
int sp;
};
stack s;
stack p;
int push(stack *,int);
int pop(stack *);
void printstack(stack *);
int isempty(stack *);
int isfull(stack *);
void move(int,char,char,char);
int fact(int n);
int main(){
s.sp=-1;
p.sp=-1;
cout<<fact(6)<<endl;
system("pause");
return 0;
}
int fact(int n){
int r;
L0:
if(n>0){
push(&p,1);push(&p,n);
n--;
goto L0;
}
else
r=1;
L1:
r=r*n;
if(!isempty(&p)){
n=pop(&p);
switch(pop(&p)){
case 1:goto L1;break;
}
}
else
return r;
}
int push(stack *p,int x){
if(isfull(p))
return 1;
p->sp++;
p->stackarray[p->sp]=x;
}
int pop(stack *p){
if(isempty(p))
return 1;
else
return p->stackarray[p->sp--];
}
int isempty(stack *p){
if(p->sp==-1)
return 1;
else
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CgojZGVmaW5lIE4gMTAwMDAKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgoKCnN0cnVjdCBzdGFja3sKCiAgICAgICBpbnQgc3RhY2thcnJheVtOXTsKCiAgICAgICBpbnQgc3A7CgogICAgICAgCgogICAgICAgCgogICAgICAgfTsKCiBzdGFjayBzOwoKIHN0YWNrIHA7CgogICAgICAgIAoKIAoKaW50IHB1c2goc3RhY2sgKixpbnQpOwoKaW50IHBvcChzdGFjayAqKTsKCnZvaWQgcHJpbnRzdGFjayhzdGFjayAqKTsKCmludCBpc2VtcHR5KHN0YWNrICopOwoKaW50IGlzZnVsbChzdGFjayAqKTsgCgp2b2lkIG1vdmUoaW50LGNoYXIsY2hhcixjaGFyKTsgCgppbnQgZmFjdChpbnQgbik7CgogICAgICAgCgppbnQgbWFpbigpewoKICAgIAoKICAgIHMuc3A9LTE7ICAKCiAgICBwLnNwPS0xOwoKICAgIAoKICAgIAoKICAgCgogICAgY291dDw8ZmFjdCg2KTw8ZW5kbDsKCiAgICAKCiAgIAoKICAgIHN5c3RlbSgicGF1c2UiKTsKCiAgICAgcmV0dXJuIDA7CgogICAgIAoKICAgICAKCiAgICAgfQoKCgoKCgoKaW50IGZhY3QoaW50IG4pewoKICAgIGludCByOwoKICAgIAoKICAgTDA6CgogICAgICAgIGlmKG4+MCl7CgogICAgICAgICAgICAgICAgcHVzaCgmcCwxKTtwdXNoKCZwLG4pOwoKICAgICAgICAgICAgICAgIG4tLTsKCiAgICAgICAgICAgICAgICBnb3RvIEwwOwoKICAgICAgICAgICAgICAKCiAgICAgICAgICAgCgogICAgICAgICAgICAgICAgfQoKICAgICAgICAgZWxzZQoKICAgICAgICAgcj0xOwoKICAgICAgICAgCgogICAgICAgCgogICAgICAgICBMMTogCgogICAgICAgICAgICAgIHI9cipuOyAgICAgICAKCiAgICAgICAgIAoKICAgICAgICAgaWYoIWlzZW1wdHkoJnApKXsKCiAgICAgICAgICAgICAgbj1wb3AoJnApOwoKICAgICAgICAgICAgICBzd2l0Y2gocG9wKCZwKSl7ICAgICAgICAgICAgCgogICAgICAgICAgICAgIGNhc2UgMTpnb3RvIEwxO2JyZWFrOyAgCgogICAgICAgICAgICAgIH0gICAgICAgICAgICAgIAoKICAgICAgICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICBlbHNlCgogICAgICAgICAgcmV0dXJuIHI7CgogICAgCgogICAgCgogICAgfQoKCgoKCgoKICAgICAKCiAgICAgCgppbnQgcHVzaChzdGFjayAqcCxpbnQgeCl7CgogICAgIGlmKGlzZnVsbChwKSkKCiAgICAgcmV0dXJuIDE7CgogICAgIHAtPnNwKys7CgogICAgIHAtPnN0YWNrYXJyYXlbcC0+c3BdPXg7CgogICAgIAoKICAgICB9CgogICAgIAoKaW50IHBvcChzdGFjayAqcCl7CgogICAgIGlmKGlzZW1wdHkocCkpCgogICAgIHJldHVybiAxOwoKICAgICBlbHNlCgogICAgIHJldHVybiBwLT5zdGFja2FycmF5W3AtPnNwLS1dOyAgICAgCgogICAgIAoKICAgICAgCgogICAgIH0gCgogICAgIAoKaW50IGlzZW1wdHkoc3RhY2sgKnApewoKICAgICBpZihwLT5zcD09LTEpCgogICAgIHJldHVybiAxOwoKICAgICBlbHNlCgogICAgIHJldHVybiAwOyAgICAgIAoKICAgICB9CgogIA==