提交时间:2023-08-22 22:21:16

运行 ID: 99511

#include <bits/stdc++.h>; using namespace std; //¶¨Òå¿Í»§½á¹¹Ìå struct user{ int k,p; }; //ÖØдcompº¯Êý bool comp(user a,user b){ return a.p < b.p; } //¶¨Òå¶ÓÁг¤¶È¡¢¶ÓÁÐ int const maxsize = 120; int len = 0; //¼ÓÈ뺯Êý void join(user _list[]){ int k,p; cin >> k >> p; _list[len].k = k; _list[len].p = p; len++; } //ÊÇ·ñΪ¿Õº¯Êý bool empty(){ return len==0; } //ɾ³ýº¯Êý int pop(int n,user _list[]){ if(empty()) return 0; sort(_list,_list+len,comp); len--; if(n == 2) return _list[len].k; else{ int tmp = _list[0].k; for(int i=0;i<len;i++) _list[i] = _list[i+1]; return tmp; } } int main(){ user list[maxsize]; int n; cin >> n; while(n != 0){ if(n == 1) join(list); else cout << pop(n,list) << endl; cin >> n; } return 0; }