Advertisement
J00ker

Untitled

Mar 25th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. #include <iostream>
  2. #define Nmax 1001
  3.  
  4. using namespace std;
  5.  
  6. struct Coada
  7. {
  8. int q[Nmax];
  9. int pr, ul;
  10.  
  11. void Init()
  12. {
  13. pr = 0;
  14. ul = - 1;
  15. }
  16.  
  17. int Empty()
  18. {
  19. if(pr <= ul) return 0;
  20. return 1;
  21. }
  22.  
  23. void Push(int x)
  24. {
  25. ul++;
  26. q[ul] = x;
  27. }
  28.  
  29. void Pop()
  30. {
  31. if(!Empty()) pr++;
  32. }
  33.  
  34. int Front()
  35. {
  36. return q[pr];
  37. }
  38.  
  39. int End()
  40. {
  41. return q[ul];
  42. }
  43.  
  44. int Size()
  45. {
  46. return ul - pr + 1;
  47. }
  48. };
  49.  
  50. int SirRecur(int k, int n)
  51. {
  52. Coada c;
  53. c.Init();
  54. int i, x, sum = 0;
  55. for(i = 0; i < k; i++)
  56. {
  57. cout << i+1 << ": "; cin >> x;
  58. c.Push(x);
  59. sum += x;
  60. }
  61. for(i = k+1; i <= n; i++)
  62. {
  63. c.Push(sum);
  64. sum *= 2;
  65. sum -= c.Front();
  66. c.Pop();
  67. }
  68. return c.End();
  69. /*
  70. c.Pop();
  71. while(!c.Empty())
  72. {
  73. cout << c.Front() << " "; c.Pop();
  74. cout << "\n";
  75. }
  76. */
  77. }
  78.  
  79. void OperatiiN(int n)
  80. {
  81. Coada c;
  82. c.Init();
  83. int x, mx = n, elem = 1;
  84.  
  85. c.Push(n);
  86. while(n > 1)
  87. {
  88. if(n % 2 == 1) n = ((3 * n) + 1);
  89. else n = n/2;
  90. if(n > mx) mx = n;
  91. c.Push(n);
  92. }
  93. cout << "Maxim: " << mx << "\n";
  94. cout << "Nr. elem: " << c.Size() << "\n";
  95. /*
  96. while(!c.Empty())
  97. {
  98. cout << c.Front() << " "; c.Pop();
  99. cout << "\n";
  100. }
  101. */
  102. }
  103.  
  104. int main()
  105. {
  106. /*
  107. int k, n;
  108. cout << "k: "; cin >> k;
  109. cout << "n: "; cin >> n;
  110. cout << SirRecur(k, n) << "\n";
  111. */
  112.  
  113. /*
  114. int n;
  115. cout << "n: "; cin >> n;
  116. OperatiiN(n);
  117. */
  118.  
  119. return 0;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement