#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
struct complex
{
int a;
int b;
bool operator <(const complex &cA)const //要有返回值
{
int mx = a*a +b*b;
int my = cA.a *cA.a + cA.b *cA.b;
if(mx == my)
{
return a < cA.a; //a大b小
}
else
{
return mx < my;
}
}
};
complex stackC[1001];//用数组代替栈来保存信息
//字符串转化数字
int strToNum(string str)
{
int tmp= 0;
int len = str.length();
for(int i =0; i< len; i++)
{
if(0 == i)
{
tmp = str[i] -'0';
}
else
tmp = 10* tmp + (str[i]-'0');
}
return tmp;
}
int main()
{
int n;//记录n条指令
int size =0;//记录有几个元素
string msg;//指令类型
string t;//记录复数字符串
string s;//
string aS;//记录数字a
string bS;//记录数字b字符串
//ifstream cin("BUPT_1178.txt");//从文件中读入数据流
while(cin >> n)
{
size =0;//每次均初始化为空栈
for(int i=0; i< n; i++)//开始输入指令
{
cin >> msg;
if("Pop" == msg) //Pop
{
if(0 == size)
{
cout << "empty" << endl;
}
else
{
sort(stackC,stackC+size);//忘了排序了
cout << stackC[size-1].a <<"+i" << stackC[size-1].b << endl;
size --;
cout << "SIZE = " << size << endl;
}
}
else //Insert
{
cin >> t;//输入复数
int len = t.length();
int j;
for(j=0; j<len ;j++)
{
if(t[j]=='+')
{
break;
}
}
aS = t.substr(0,j);
bS = t.substr(j+2);
//cout << j << " " <<aS << " " << bS << endl;
int a = strToNum(aS);
int b = strToNum(bS);
stackC[size].a = a;
stackC[size].b = b;
size++;
cout << "SIZE = " << size << endl;
}
}
}
// getchar();//
return 0;
}
/**************************************************************
Problem: 1178
User: itswyy
Language: C++
Result: Accepted
Time:20 ms
Memory:1532 kb
****************************************************************/