Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long int ll;
- ll operation,top,ind,q[100000];
- map<ll,ll>word;
- void add(ll u)
- {
- ll flag=0;
- for(ll i=1; i<=ind; i++)
- {
- if(q[i]==u)
- {
- flag=1;
- break;
- }
- }
- if(flag==0)
- {
- q[++ind]=u;
- word[u]=0;
- cout<<"Operation #"<<operation++<<": success."<<endl;
- }
- else
- {
- cout<<"Operation #"<<operation++<<": same priority."<<endl;
- }
- }
- void close(ll u)
- {
- ll flag=0,index;
- if(top==u)
- {
- top=-1;
- }
- for(ll i=1; i<=ind; i++)
- {
- if(q[i]==u)
- {
- index=i;
- flag=1;
- break;
- }
- }
- if(flag==0)
- cout<<"Operation #"<<operation++<<": invalid priority."<<endl;
- else
- {
- cout<<"Operation #"<<operation++<<": close "<<u <<" with "<<word[u]<<"."<<endl;
- for(ll j=index; j<ind; j++)
- q[j]=q[j+1];
- ind--;
- }
- }
- void chat(ll w)
- {
- if(top!=-1)
- {
- word[top]+=w;
- cout<<"Operation #"<<operation++<<": success."<<endl;
- }
- else
- {
- ll flag=0;
- if(ind!=0)
- {
- flag=1;
- }
- if(flag==1)
- {
- word[q[1]]+=w;
- cout<<"Operation #"<<operation++<<": success."<<endl;
- }
- else
- {
- cout<<"Operation #"<<operation++<<": empty."<<endl;
- }
- }
- }
- void Rotate(ll u)
- {
- ll flag=0;
- if(u<1 || u>ind)
- {
- flag=1;
- }
- if(flag==0)
- {
- ll far=q[u];
- for(ll i=u; i>=1; i--)
- {
- q[i]=q[i-1];
- }
- q[1]=far;
- cout<<"Operation #"<<operation++<<": success."<<endl;
- }
- else
- {
- cout<<"Operation #"<<operation++<<": out of range."<<endl;
- }
- }
- void prior()
- {
- ll mx=-1e9,flag=-1;
- for(ll i=1; i<=ind; i++)
- {
- if(q[i]>mx)
- {
- mx=q[i];
- flag=i;
- }
- }
- if(flag==-1)
- {
- cout<<"Operation #"<<operation++<<": empty."<<endl;
- }
- else
- {
- Rotate(flag);
- }
- }
- void choose(ll u)
- {
- ll flag=0,index;
- for(ll i=1; i<=ind; i++)
- {
- if(q[i]==u)
- {
- flag=1;
- index=i;
- break;
- }
- }
- if(flag==0)
- {
- cout<<"Operation #"<<operation++<<": invalid priority."<<endl;
- }
- else
- {
- Rotate(index);
- }
- }
- void Top(ll u)
- {
- ll flag=0;
- for(ll i=1; i<=ind; i++)
- {
- if(q[i]==u)
- {
- flag=1;
- break;
- }
- }
- if(flag==0)
- cout<<"Operation #"<<operation++<<": invalid priority."<<endl;
- else
- {
- top=u;
- cout<<"Operation #"<<operation++<<": success."<<endl;
- }
- }
- void untop()
- {
- if(top==-1)
- {
- cout<<"Operation #"<<operation++<<": no such person."<<endl;
- }
- else
- {
- top=-1;
- cout<<"Operation #"<<operation++<<": success."<<endl;
- }
- return;
- }
- void bye()
- {
- if(top!=-1 && word[top])
- {
- cout<<"Bye "<<top<<": "<<word[top]<<endl;
- }
- for(ll i=1; i<=ind; i++)
- {
- if(q[i]!=top && word[q[i]])
- {
- cout<<"Bye "<<q[i]<<": "<<word[q[i]]<<endl;
- }
- }
- }
- int main()
- {
- ll t,i,j,k,n,cas,a;
- cin>>t;
- while(t--)
- {
- cin>>n;
- ind=0,top=-1,operation=1;
- word.clear();
- while(n--)
- {
- string s;
- ll w,u,x,y,z;
- cin>>s;
- if(s=="Add")
- {
- cin>>u;
- add(u);
- }
- else if(s=="Close")
- {
- cin>>u;
- close(u);
- }
- else if(s=="Chat")
- {
- cin>>w;
- chat(w);
- }
- else if(s=="Rotate")
- {
- cin>>x;
- Rotate(x);
- }
- else if(s=="Prior")
- {
- prior();
- }
- else if(s=="Choose")
- {
- cin>>u;
- choose(u);
- }
- else if(s=="Top")
- {
- cin>>u;
- Top(u);
- }
- else if(s=="Untop")
- {
- untop();
- }
- }
- bye();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement