Analysis:
Priority queue questions.
Note that the priority queue should be defined in the large while, which is equivalent
Initialization is empty.
# Include <stdio. h>
# Include <string. h>
# Include <queue>
Char A [100];
Using namespace STD;
Struct point
{
Int X, Y;
Friend bool operator <(point a, point B)
{
If (A. Y! = B. Y)
Return A. Y <B. Y; ----- priority ..
Return A. x> B. X ..
}
};
Int main ()
{
Int m, n, k, I, j, P;
Point cur;
While (scanf ("% d", & M )! = EOF)
{
Priority_queue <point> q [4]; ---------- Q [4] is good ..
J = 1;
For (I = 0; I <m; I ++)
{
Scanf ("% s", );
If (strcmp (a, "in") = 0)
{
Scanf ("% d", & P, & K );
Cur. x = J;
Cur. Y = K;
Q [p]. Push (cur);, join ,,
J ++;
}
Else if (strcmp (a, "out") = 0)
{
Scanf ("% d", & N );
If (Q [N]. Empty () ----- if it is null
Printf ("Empty \ n ");
Else
{
Cur = Q [N]. Top ();
Q [N]. Pop ();
Printf ("% d \ n", cur. X );
}
}
}
}
Return 0;
}
Common method: struct (timeout if the number is large) # include <stdio. h>
# Include <string. h>
Struct point
{
Int x, y, z;
} P [10000];
Int main ()
{
Int m, I, J, K, H, R, T;
Char A [100];
While (scanf ("% d", & M )! = EOF)
{
T = 1;
For (I = 1; I <= m; I ++)
{
Scanf ("% s", );
If (strcmp (a, "in") = 0)
{
Scanf ("% d", & P [T]. X, & P [T]. y );
P [T]. z = T;
T ++;
}
Else
{
Scanf ("% d", & K );
H = 0, r = 0;
For (j = 1; j <t; j ++)
{
If (P [J]. x = K & P [J]. Y> H)
{
H = P [J]. Y;
R = J;
}
}
P [R]. Y = 0;
If (H! = 0)
Printf ("% d \ n", P [R]. z );
Else
Printf ("Empty \ n ");
}
}
}
Return 0;
}