题解 | 复数
#include <bits/stdc++.h>
using namespace std;
struct cp{
int a;
int b;
cp(int a,int b):a(a),b(b){};
cp operator +(cp x){
return cp(a+x.a,b+x.b);
}
};
int main(){
int n;
while(cin>>n){
while(n--){
int a1,a2,b1,b2;
cin>>a1>>a2>>b1>>b2;
cp x=cp(a1,a2);
cp y=cp(b1,b2);
cp z=x+y;
if(z.b>=0){
cout<<z.a<<"+"<<z.b<<"i"<<endl;
}else cout<<z.a<<z.b<<"i"<<endl;
}
}
}
本题核心就是你会写struct的符号改写方法,然后注意,本题0我们认为是加号
