ZOJ 2724 Windows Message Queue£¨¶Ô½á¹¹ÌåʹÓÃÓÅÏȶÓÁУ© /* * ZOJ_2724.cpp * * Created on: 2013Äê11ÔÂ7ÈÕ * Author: Administrator */ #include <iostream> #include <cstdio> #include <cstring> #include <queue> using namespace std; struct MES { char str ; int mes; int p; int id; bool operator<£¨ const MES& b£©const {//ÌØ±ðҪעÒâÕâÖÖд·¨¡ if £¨p != b.p£© { return p > b.p; } return id > b.id; } }; int main£¨£© { char s[26]; priority_queue<MES> q;//¶Ô½á¹¹ÌåʹÓÃÓÅÏȶÓÁÐ MES tmp; while £¨scanf£¨"%s", s£© != EOF£© { int index = 0; if £¨strcmp£¨s, "PUT"£© == 0£© { scanf£¨"%s %d %d", tmp.str, &tmp.mes, &tmp.p£©£» tmp.id = index++; q.push£¨tmp£©£» } else { if £¨q.empty£¨£©£© { printf£¨"EMPTY QUEUE!\n"£©£» } else { tmp = q.top£¨£©£» q.pop£¨£©£» printf£¨"%s %d\n", tmp.str, tmp.mes£©£» } } } return 0; } |