Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define Nmax 1001
- using namespace std;
- struct Coada
- {
- int q[Nmax];
- int pr, ul;
- void Init()
- {
- pr = 0;
- ul = - 1;
- }
- int Empty()
- {
- if(pr <= ul) return 0;
- return 1;
- }
- void Push(int x)
- {
- ul++;
- q[ul] = x;
- }
- void Pop()
- {
- if(!Empty()) pr++;
- }
- int Front()
- {
- return q[pr];
- }
- int End()
- {
- return q[ul];
- }
- int Size()
- {
- return ul - pr + 1;
- }
- };
- int SirRecur(int k, int n)
- {
- Coada c;
- c.Init();
- int i, x, sum = 0;
- for(i = 0; i < k; i++)
- {
- cout << i+1 << ": "; cin >> x;
- c.Push(x);
- sum += x;
- }
- for(i = k+1; i <= n; i++)
- {
- c.Push(sum);
- sum *= 2;
- sum -= c.Front();
- c.Pop();
- }
- return c.End();
- /*
- c.Pop();
- while(!c.Empty())
- {
- cout << c.Front() << " "; c.Pop();
- cout << "\n";
- }
- */
- }
- void OperatiiN(int n)
- {
- Coada c;
- c.Init();
- int x, mx = n, elem = 1;
- c.Push(n);
- while(n > 1)
- {
- if(n % 2 == 1) n = ((3 * n) + 1);
- else n = n/2;
- if(n > mx) mx = n;
- c.Push(n);
- }
- cout << "Maxim: " << mx << "\n";
- cout << "Nr. elem: " << c.Size() << "\n";
- /*
- while(!c.Empty())
- {
- cout << c.Front() << " "; c.Pop();
- cout << "\n";
- }
- */
- }
- int main()
- {
- /*
- int k, n;
- cout << "k: "; cin >> k;
- cout << "n: "; cin >> n;
- cout << SirRecur(k, n) << "\n";
- */
- /*
- int n;
- cout << "n: "; cin >> n;
- OperatiiN(n);
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement