Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int n;
- struct Stiva
- {
- int a[1001], top;
- void Init()
- {
- top = -1;
- }
- int Empty()
- {
- if(top == -1) return 1;
- return 0;
- }
- int Full()
- {
- if(top == n-1) return 1;
- return 0;
- }
- void Push(int x)
- {
- a[++top] = x;
- }
- void Pop()
- {
- if(!Empty()) top--;
- }
- int Top()
- {
- if(Empty()) return 0;
- return a[top];
- }
- };
- int main()
- {
- Stiva s, s1, s2;
- s.Init();
- s1.Init();
- s2.Init();
- int i, x, f = 0;
- ifstream fin("s1.in");
- fin >> n;
- for(i = 0; i < n; i++)
- {
- fin >> x;
- s1.Push(x);
- }
- fin.close();
- while(!s2.Full() && f == 0)
- {
- x = s1.Top();
- s1.Pop();
- if(x == s2.Top() + 1)
- {
- s2.Push(x); cout << 1 << "\n";
- }
- else if(x > s.Top())
- {
- s.Push(x); cout << 2 << "\n";
- }
- if(s.Top() == s2.Top() + 1)
- {
- s2.Push(s.Top()); cout << 3 << "\n";
- s.Pop();
- }
- if((s1.Top() != s2.Top()+1) && (s.Top() > s2.Top()))
- f++;
- }
- if(s2.Full()) cout << "da";
- else cout << "nu";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement