1. Title Narrative Description: Click to open the link
2. How to solve the problem: according to a possible data structure, the alternative answer is "stack, queue." Priority queue ". The results may also be either not or uncertain.
There are already three data structures in the STL, so it is possible to directly simulate the test instructions and infer whether the output is appropriate. Note: You should infer if it is empty when it pops up.
3. Code:
#define _crt_secure_no_warnings #include <iostream> #include <algorithm> #include <string> #include <sstream> #include <set> #include <vector> #include <stack> #include <map> #include < queue> #include <deque> #include <cstdlib> #include <cstdio> #include <cstring> #include < cmath> #include <ctime> #include <functional>using namespace std;stack<int>s;queue<int>q; Priority_queue<int>p;char st[][20] = {' Impossible ', ' priority queue ', ' queue ', ' not sure ', ' stack ', ' not sure ', ' not ' Sure "," not sure "};void clear () {while (!s.empty ()) S.pop (), while (!q.empty ()) Q.pop (), while (!p.empty ()) P.pop ();} void Add (int x) {s.push (x); Q.push (x);p. push (x);} void Pop () {if (!s.empty ()) S.pop (), if (!q.empty ()) Q.pop (), if (!p.empty ()) P.pop ();} int main () {//freopen ("T.txt", "R", stdin), int n;while (~SCANF ("%d", &n)) {clear (); int Ok1, ok2, Ok3;ok1 = Ok2 = OK3 = 1 ; for (int i = 0; i < n; i++) {int A, b;cin >> a >> b;if (a= = 1) add (b);//Unified Join ELSE{IF (S.empty () | | | s.top ()! = b) Ok1 = 0;if (Q.empty () | | Q.front ()! = b) Ok2 = 0;if (P.empty () | | | p.to P ()! = b) Ok3 = 0;pop ();//Unified eject}}int x = (ok1 << 2) | (ok2 << 1) | ok3;//encoding, easy to output results printf ("%s\n", St[x]);} return 0;}
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
Example 3.1 Guess data structure UVa11995