Nita_Cristian

coada1

Mar 5th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. //Dragan Andrei Gabriel
  2. //University of Bucharest
  3.  
  4. #include <cstdio>
  5. #include <cstring>
  6. #include <algorithm>
  7.  
  8. using namespace std;
  9.  
  10. int v[1001], coada[50001], dim, m, x, indx;
  11. char s[10];
  12.  
  13. int main()
  14. {
  15.     freopen("coada1.in", "r", stdin);
  16.     freopen("coada1.out", "w", stdout);
  17.  
  18.     scanf("%d", &m);
  19.  
  20.     indx = 0, dim = 0;
  21.  
  22.     while (m--)
  23.     {
  24.         scanf("%s %d", s, &x);
  25.         if (strcmp(s, "push") == 0)
  26.         {
  27.             if (v[x] > indx)
  28.                 indx = v[x], coada[++dim] = x, v[x] = dim;
  29.                 else
  30.                     if (v[x] <= indx)
  31.                         coada[++dim] = x, v[x] = dim;
  32.         }else
  33.         {
  34.             if (v[x] > indx)
  35.                 printf("%d\n", v[x] - indx);
  36.                 else
  37.                     printf("-1\n");
  38.         }
  39.     }
  40.  
  41.     return 0;
  42. }
Add Comment
Please, Sign In to add comment