hdu 2020
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2020
思路:优先队列水过priority_queue
1 #include <cstdio> 2 #include <iostream> 3 #include<algorithm> 4 #include<math.h> 5 #include <string.h> 6 #include<queue> 7 using namespace std; 8 9 10 class T 11 { 12 public: 13 int x; 14 T(int a):x(a) 15 { 16 17 } 18 19 }; 20 21 22 bool operator < (const T &t1,const T &t2) 23 { 24 return fabs(t1.x)<fabs(t2.x); //常规降序 25 } 26 27 int main() 28 { 29 int num,n; 30 while(scanf("%d",&num),num) 31 { 32 priority_queue<T> q; 33 34 for(int i=0;i<num;i++) 35 { 36 scanf("%d",&n); 37 q.push(T(n)); 38 } 39 int len=q.size(); 40 for(int i=0;i<len-1;i++) 41 { 42 T t=q.top();q.pop(); 43 cout<<t.x<<" "; 44 } 45 T a=q.top(); 46 cout<<a.x<<endl; 47 } 48 return 0; 49 50 } 51