Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include<cstdio>
  2. #include<queue>
  3. using namespace std;
  4. queue<int>q;
  5. bool v[1005];
  6. int findd(int x, queue<int>t)
  7. {
  8. while(t.back()==x)
  9. t.pop();
  10. return t.size();
  11. }
  12. int main()
  13. {
  14. freopen("coada1.in","r",stdin);
  15. freopen("coada1.out","w",stdout);
  16. int n,x;
  17. char ch,ch2,ch3,ch4,ch1;
  18. scanf("%d\n",&n);
  19. for(register int i=1;i<=n;i++)
  20. {
  21. scanf("%c",&ch);
  22. if(ch=='p')
  23. {
  24. scanf("%c%c%c ",&ch1,&ch2,&ch3);
  25. scanf("%d\n",&x);
  26. if(v[x]==0)
  27. {
  28. q.push(x);
  29. v[x]=1;
  30. }
  31. else
  32. {
  33. while(q.back()!=x)
  34. {
  35. v[q.back()]=0;
  36. q.pop();
  37. }
  38. v[x]=1;
  39. }
  40. }
  41. else
  42. {
  43. scanf("%c%c%c%c ",&ch1,&ch2,&ch3,&ch4);
  44. scanf("%d\n",&x);
  45. if(v[x]==0) printf("-1\n");
  46. else printf("%d\n",findd(x,q));
  47. }
  48. }
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement