//C++类
//复数计算器,支持复数的加减乘除,
//对于该结果的输出方式,要分很多情况,本人 数学特别差,但提交平台又有特殊要求
//台州学院 2017/5/3Left-Behind
#include
#include
#include
#include
using namespace std;
string str;
class Complex
{
private:
double real;
double imag;
public:
friend ostream&operator<<(ostream &out, const Complex &c);
friend istream&operator >> (istream &in, Complex &c);
Complex operator+(const Complex &b)
{
Complex re;
re.real = this->real + b.real;
re.imag = this->imag + b.imag;
return re;
}
Complex operator-(const Complex &b)
{
Complex re;
re.real = this->real - b.real;
re.imag = this->imag - b.imag;
return re;
}
Complex operator*(const Complex &b)
{
Complex re;
re.real = this->real * b.real - this->imag*b.imag;
re.imag = this->real*b.imag + b.real*this->imag;
return re;
}
Complex operator/(const Complex &b)
{
Complex re;
re.real = (this->real*b.real + this->imag*b.imag)*1.0 / (b.real*b.real + b.imag*b.imag);
re.imag = (this->imag*b.real - this->real*b.imag)*1.0 / (b.real*b.real + b.imag*b.imag);
return re;
}
};
ostream & operator<<(ostream &out, const Complex &c)
{
if (c.imag == 0 && c.real == 0)
out << "0.0" << endl;
else if (c.real == 0 && c.imag != 0)
{
if (c.imag == 1)
cout << "i" << endl;
else if (c.imag == -1)
cout << "-1" << endl;
else
out << setiosflags(ios::fixed) << setprecision(1) << c.imag << "i" << endl;
}
else if (c.real != 0 && c.imag == 0)
out << setiosflags(ios::fixed) << setprecision(1) << c.real << endl;
else if (c.imag == 1)
out << setiosflags(ios::fixed) << setprecision(1) << c.real << "+i" << endl;
else if (c.imag>0)
out << setiosflags(ios::fixed) << setprecision(1) << c.real << "+" << setprecision(1) << c.imag << "i" << endl;
else
{
if (c.imag == -1)
out << setiosflags(ios::fixed) << setprecision(1) << c.real << "-i" << endl;
else
out << setiosflags(ios::fixed) << setprecision(1) << c.real << setprecision(1) << c.imag << endl;
}
return out;
}
istream & operator >> (istream &in, Complex &c)
{
in >> c.real >> c.imag;
return in;
}
int main()
{
int t;
cin >> t;
while (t--)
{
Complex n, m;
cin >> n;
cin >> str;
cin >> m;
if (str == "+")
cout << n + m;
else if (str == "-")
cout << n - m;
else if (str == "*")
cout << n * m;
else
cout << n / m;
}
}