[Cpp]/********************************** * ***** question: code = 1 then k is in the queue, and k has a priority of p; code = 2: Process columns with the highest priority; code = 3: Process columns with the lowest priority; algorithm idea: Use map in STL for processing, because map can be automatically sorted; Use priority p as the map keyword; each inserted element map will be automatically sorted; output as required; **************************************** **/# include <iostream> # include <algorithm> # include <stack> # include <cstring> # include <cstdlib> # include <cstdio> # include <map> using namespace std; int main (){// Freopen ("C :\\ Users \ Administrator \ Desktop \ kd.txt", "r", stdin); int code; map <int, int> Map; while (scanf ("% d", & code) {if (code = 1) {int k, p; scanf ("% d ", & k, & p); Map [p] = k;} else if (code = 3) {if (! Map. empty () {printf ("% d \ n", Map. begin ()-> second); Map. erase (Map. begin (); // Delete the first element of the queue in the order} else puts ("0");} else {if (! Map. empty () {www.2cto.com printf ("% d \ n", Map. rbegin ()-> second); Map. erase (Map. find (Map. rbegin ()-> first); // Delete the first element of the reverse queue. Note the difference between this element and the deleted ordered queue.} else puts ("0") ;}} return 0 ;}