#include<iostream>
#include<string>
using namespace std;
class complex
{
public:
complex(){}
complex(double m,double n)
{
this->m=m;
this->n=n;
}
complex &operator+(complex &s)
{
complex c;
c.m=m+s.m;
c.n=n+s.n;
return c;
}
complex &operator-(complex &s)
{
complex c;
c.m=m-s.m;
c.n=n-s.n;
return c;
}
complex &operator*(complex &s)
{
complex c;
c.m=(m*s.m)-(n*s.n);
c.n=(n*s.m)+(m*s.n);
return c;
}
complex &operator/(complex &s)
{
complex c;
c.m=((m*s.m)+(n*s.n))/(s.m*s.m+s.n*s.n);
c.n=((n*s.m)-(m*s.n))/(s.m*s.m+s.n*s.n);
return c;
}
void show()
{
if(m==0&&n!=0)
cout<<n<<"i"<<endl;
else if(n<0)
cout<<m<<"-"<<n<<"i"<<endl;
else if(n==0&&m!=0)
cout<<m<<endl;
else
cout<<m<<"+"<<n<<"i"<<endl;
}
private:
double m,n;
};
int main()
{
int t;
double m,n,m1,n1;
char c;
cin>>t;
for(int i=0;i<t;i++)
{
cin>>m>>n;
complex a(m,n);
cin>>c;
while(c!='=')
{
if(c=='+')
{
cin>>m>>n;
complex b(m,n);
a=a+b;
}
else if(c=='-')
{
cin>>m>>n;
complex b(m,n);
a=a-b;
}
else if(c=='*')
{
cin>>m>>n;
complex b(m,n);
a=a*b;
}
else if(c=='/')
{
cin>>m1>>n1;
complex b(m1,n1);
a=a/b;
}
cin>>c;
}
if(c=='=')
{
if(m1!=0&&n1!=0)
{
a.show();
continue;
}
else
{
cout<<"divide by zero"<<endl;
}
}
}
}
慕盖茨8171496
慕盖茨8171496
AAnonymous
相关分类