1 8 1 1 1 1 1 1 1 1 2 1 2 1 1 2 2 2 1 1 2 1 2 2 2 1
1 1 1 1 2 1 1 2 2 2 1 1 2 2 1
#include<iostream>
#include<queue>
#include<vector>
using 
  namespace std;
class squar
{
	int NO;
	int lenth;
	int 
  width;
public:
	void SetNO(){cin>>NO;}
	void 
  SetLenth(){cin>>lenth;}
	void SetWidth(){cin>>width;}
	int 
  GetNO() const{return NO;}
	int GetLenth() const{return lenth;}
	int 
  GetWidth() const{return width;}
	bool operator<(const squar& 
  s)const
	{
		int NO1=s.GetNO();
		int lenth1=s.GetLenth();
		int 
  width1=s.GetWidth();
		if(NO>NO1) return 
  true;
		if((NO==NO1)&&(lenth>lenth1)) return 
  true;
		if((NO==NO1)&&(lenth==lenth1)&&(width>width1)) 
  return 
  true;
		//if((NO==NO1)&&(lenth==lenth1)&&(width==width1)) 
  
		return false;
	}
};
int main()
{
	squar s[100];
	int 
  n,i=0;
	cin>>n;	
	while(i<n)
	{
	//初始化该数组
s[i].SetNO();
		s[i].SetLenth();
		s[i].SetWidth();
		i++;
	}
	priority_queue<squar>pr(s,s+n); 
     
  //降序排序成功了,但是升序还是不行,priority_queue<squar,vector,greater<squar>>pr(s,s+n);
	while(!pr.empty())
	{
 
         squar& 
  t=pr.top();
		cout<<t.GetNO()<<"\t"<<t.GetLenth()<<"\t"<<t.GetWidth()<<endl;
		pr.pop();
	}
	return 
  0;
}
//这题没有实现完全,还有一个功能没有实现:即不能去掉重复的元素————————————————————————
待续
优先队列 的实例(未完----待续),布布扣,bubuko.com
原文:http://www.cnblogs.com/zdblog/p/3632193.html