fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main()
  5. {
  6. int a, num;
  7. int count = 0;
  8. scanf("%d", &a);
  9. char s[100];
  10. int arr[10001] = { 0, }; //que 배열
  11. for (int i = 0; i < a; i++)
  12. {
  13. scanf("%s", s);
  14. if (!strcmp(s, "push"))
  15. {
  16. scanf("%d", &num);
  17. arr[count] = num;
  18. count++;
  19. }
  20.  
  21. if (!strcmp(s, "pop"))
  22. {
  23. if (count == 0)printf("-1\n");
  24. else {
  25. printf("%d\n", arr[0]);
  26. for (int j = 0; j < count; j++)
  27. {
  28. arr[j] = arr[j + 1];
  29. }
  30. count--;
  31. }
  32. }
  33.  
  34. if (!strcmp(s, "size"))
  35. {
  36. printf("%d\n", count);
  37. }
  38.  
  39. if (!strcmp(s, "empty"))
  40. {
  41. if (count == 0)
  42. printf("1\n");
  43. else
  44. {
  45. printf("0\n");
  46. }
  47.  
  48. }
  49.  
  50. if (!strcmp(s, "front"))
  51. {
  52. if (arr[0] == '0')printf("-1\n");
  53. else
  54. {
  55. printf("%d\n", arr[0]);
  56. }
  57. }
  58.  
  59. if (!strcmp(s,"back"))
  60. {
  61. if (count == '0')printf("-1");
  62. else
  63. {
  64. printf("%d\n", arr[count-1]);
  65.  
  66. }
  67. }
  68. }
  69. return 0;
  70. }
Success #stdin #stdout 0.01s 5280KB
stdin
10
push 1
push 2
front
back
pop
size
pop
size
front
back
stdout
1
2
1
1
2
0
0
2