BUPT OJ 虛數

#include<iostream>
#include<queue>
#include<string>
#include<cstdio>
using namespace std;
class complex
{
	public:
	int real;
	int image;
	complex(int a=0,int b=0)
	{
		real=a;
		image=b;
	}	
};
class cmp
{
	public:
	bool operator()(complex a,complex b)
	{
		
		return a.real*a.real+a.image*a.image<b.real*b.real+b.image*b.image;
		
	}
};
int main()
{
	string command;
     int t,n,a,b;
     cin>>t;
	while(t--)
	{
		priority_queue<complex,vector<complex>,cmp>qe;
		cin>>n;
		while(n--)
			{
				
				cin>>command;
				if(command=="Insert"){
				scanf("%d+i%d",&a,&b);
				complex temp(a,b);
				qe.push(temp);
				cout<<"Size: "<<qe.size()<<endl;
									}
					else{
						if(qe.empty())cout<<"Empty!\n";
						else{
						
						cout<<qe.top().real<<"+i"<<qe.top().image<<endl;
							qe.pop();
							if(qe.empty())cout<<"Empty!\n";
							else cout<<"Size: "<<qe.size()<<endl;
							}
					}
			
			
			}
		
		
	}
} 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章