Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- typedef struct mutare{char deUnde, unde; mutare *urm;};
- typedef struct nod{int info; nod *urm;};
- nod *stivaA=NULL, *stivaB=NULL;
- mutare *capMutari, *sfMutari;
- int u=0, nrMutari, i, n, x, ok = 1;
- void push(nod*&st,int x)
- {
- nod *p=new nod({x,st});
- st=p;
- }
- int pop(nod *&st)
- {
- int x=st->info;
- nod *p=st;
- st=st->urm;
- delete p;
- return x;
- }
- void add(char deUnde, char unde)
- {
- mutare *p = new mutare({deUnde, unde, NULL});
- nrMutari++;
- if(sfMutari == NULL)
- capMutari = p;
- else
- sfMutari->urm = p;
- sfMutari = p;
- }
- int main()
- {
- cin >> n;
- for(i=1; i<=n; i++){ cin >> x; push(stivaA,x); }
- while (u < n && ok == 1)
- {
- // incerc sa mut din A in C
- if(stivaA != NULL && stivaA->info == u + 1)
- {
- u++;
- pop(stivaA);
- add('A','C');
- }
- else //incerc sa mut din B in C
- if(stivaB != NULL && stivaB->info == u + 1)
- {
- u++;
- pop(stivaB);
- add('B','C');
- }
- else // mut din A in B
- if(stivaA!=NULL)
- {push(stivaB,pop(stivaA));add('A','B');}
- else
- ok = 0;
- }
- nrMutari *= ok;
- cout << nrMutari <<"\n";
- if(nrMutari > 0)
- while(capMutari != NULL) { cout<<capMutari->deUnde<<" "<<capMutari->unde<<"\n";capMutari = capMutari->urm;}
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement