fork(1) download
  1. #include <iostream>
  2. #include <queue>
  3. #include <string.h>
  4. using namespace std;
  5.  
  6. int main() {
  7. std::ios::sync_with_stdio(false);
  8. int N, i, var;
  9. char command[5];
  10.  
  11. queue<int> Queue;
  12. cin >> N;
  13. for(i=0; i<N; i++) {
  14. cin >> command;
  15. if(!strcmp("push", command)) {
  16. cin >> var;
  17. Queue.push(var);
  18. } else if(!strcmp("pop", command)) {
  19. if(Queue.size()<1)
  20. cout <<"-1\n";
  21. else {
  22. cout << Queue.front() <<"\n";
  23. Queue.pop();
  24. }
  25.  
  26. } else if(!strcmp("size", command)) {
  27. cout << Queue.size() <<"\n";
  28. Queue.size();
  29.  
  30. } else if(!strcmp("empty", command)) {
  31. cout << Queue.empty() <<"\n";
  32.  
  33. } else if(!strcmp("front", command)) {
  34. if(Queue.size()<1)
  35. cout <<"-1\n";
  36. else
  37. cout << Queue.front() << "\n";
  38.  
  39. } else if(!strcmp("back", command)) {
  40. if(Queue.size()<1)
  41. cout <<"-1\n";
  42. else
  43. cout << Queue.back() <<"\n";
  44.  
  45. }
  46.  
  47. }
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0s 4392KB
stdin
15
push 1
push 2
front
back
size
empty
pop
pop
pop
size
empty
pop
push 3
empty
front
stdout
1
2
2
0
1
2
-1
0
1
-1
0
3