Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<cstdio>
- #include<queue>
- using namespace std;
- queue<int>q;
- bool v[1005];
- int findd(int x, queue<int>t)
- {
- while(t.back()==x)
- t.pop();
- return t.size();
- }
- int main()
- {
- freopen("coada1.in","r",stdin);
- freopen("coada1.out","w",stdout);
- int n,x;
- char ch,ch2,ch3,ch4,ch1;
- scanf("%d\n",&n);
- for(register int i=1;i<=n;i++)
- {
- scanf("%c",&ch);
- if(ch=='p')
- {
- scanf("%c%c%c ",&ch1,&ch2,&ch3);
- scanf("%d\n",&x);
- if(v[x]==0)
- {
- q.push(x);
- v[x]=1;
- }
- else
- {
- while(q.back()!=x)
- {
- v[q.back()]=0;
- q.pop();
- }
- v[x]=1;
- }
- }
- else
- {
- scanf("%c%c%c%c ",&ch1,&ch2,&ch3,&ch4);
- scanf("%d\n",&x);
- if(v[x]==0) printf("-1\n");
- else printf("%d\n",findd(x,q));
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement