Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6. int iter;
  7. bool q;
  8. bool s;
  9. bool pq;
  10. int oper;
  11. int value;
  12. int max;
  13. int maxindex;
  14. vector <int> list;
  15. while (scanf("%d", &iter) != EOF) {
  16. max = 0;
  17. maxindex = -1;
  18. q = true;
  19. s = true;
  20. pq = true;
  21. printf("_____\n");
  22. printf("%d\n", list.size());
  23. for (int i = 0; i < iter; i += 1) {
  24. scanf("%d %d", &oper, &value);
  25. if (oper == 1) {
  26. list.push_back(value);
  27. if (list.size() == 1) {
  28. max = list.at(0);
  29. }
  30. else {
  31. if (value > max) {
  32. max = value;
  33. maxindex = list.size() - 1;
  34. }
  35. }
  36. }
  37. else {
  38. if (list.size() == 0) {
  39. q = false;
  40. s = false;
  41. pq = false;
  42. }
  43. else {
  44. if (list.front() != value) {
  45. q = false;
  46. }
  47. if (list.back() != value) {
  48. s = false;
  49. }
  50. if (max != value) {
  51. pq = false;
  52. }
  53. if (max == value) {
  54. list.erase(list.begin() + maxindex);
  55. if (list.size() == 0) {
  56. max = 0;
  57. maxindex = -1;
  58. }
  59. else {
  60. max = list.at(0);
  61. maxindex = 0;
  62. for (int j = 1; j < list.size(); j += 1) {
  63. if (list.at(j) > max) {
  64. max = list.at(j);
  65. maxindex = j;
  66. }
  67. }
  68. }
  69. }
  70. else if (list.at(0) == value) {
  71. list.erase(list.begin());
  72. maxindex -= 1;
  73. }
  74. else if (list.at(list.size() - 1) == value) {
  75. list.pop_back();
  76. maxindex -= 1;
  77. }
  78. }
  79. }
  80. }
  81. list.clear();
  82. if (q == 0 && s == 0 && pq == 0) {
  83. printf("impossible\n");
  84. }
  85. else if (q == 1 && s == 0 && pq == 0) {
  86. printf("queue\n");
  87. }
  88. else if (q == 0 && s == 1 && pq == 0) {
  89. printf("stack\n");
  90. }
  91. else if (q == 0 && s == 0 && pq == 1) {
  92. printf("priority queue\n");
  93. }
  94. else {
  95. printf("not sure\n");
  96. }
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement