Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. class st{
  4. private:
  5. int top;
  6. int STACK[100];
  7. public:
  8. int Create(){
  9. top = 0;
  10. }
  11. int howhigh(){return top;}
  12. int isempty(){return (top==0?1:0);}
  13. int push(int cine)
  14. {
  15. if(howhigh()<100)
  16. STACK[++top]=cine;
  17. return 0;
  18. }
  19. int pop()
  20. {
  21. if (isempty())
  22. return 0;
  23. return STACK[top--];
  24. }
  25. int tops()
  26. {
  27. return STACK[top];
  28. }
  29. };
  30.  
  31. int mp(int x);
  32.  
  33. int main()
  34. {
  35. int x;
  36. cin>>x;
  37. cout<<mp(x)<<endl;
  38. return 0;
  39. }
  40.  
  41. int mp(int x)
  42. {
  43. st Stiva;
  44. Stiva.Create();
  45. Stiva.push(x);
  46.  
  47. int fost1, fost2;
  48. while(Stiva.howhigh() > 0)
  49. {
  50. if(Stiva.tops() < 12)
  51. {
  52. Stiva.push(Stiva.tops()+2);
  53. }
  54. else
  55. {
  56. fost1 = Stiva.pop();
  57. if((fost2 = Stiva.pop()))
  58. Stiva.push(fost1 - 1);
  59. }
  60. }
  61. Stiva.push(fost1-1);
  62.  
  63. return Stiva.pop();
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement