Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class st{
- private:
- int top;
- int STACK[100];
- public:
- int Create(){
- top = 0;
- }
- int howhigh(){return top;}
- int isempty(){return (top==0?1:0);}
- int push(int cine)
- {
- if(howhigh()<100)
- STACK[++top]=cine;
- return 0;
- }
- int pop()
- {
- if (isempty())
- return 0;
- return STACK[top--];
- }
- int tops()
- {
- return STACK[top];
- }
- };
- int mp(int x);
- int main()
- {
- int x;
- cin>>x;
- cout<<mp(x)<<endl;
- return 0;
- }
- int mp(int x)
- {
- st Stiva;
- Stiva.Create();
- Stiva.push(x);
- int fost1, fost2;
- while(Stiva.howhigh() > 0)
- {
- if(Stiva.tops() < 12)
- {
- Stiva.push(Stiva.tops()+2);
- }
- else
- {
- fost1 = Stiva.pop();
- if((fost2 = Stiva.pop()))
- Stiva.push(fost1 - 1);
- }
- }
- Stiva.push(fost1-1);
- return Stiva.pop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement