1 条题解
-
0
C++ :
#include <iostream> using namespace std; class Complex { int real,imag; public: Complex( ):real(0),imag(0){} Complex(int r,int i):real(r),imag(i){} friend Complex operator *(Complex& c1,Complex& c2); friend istream & operator>>(istream & input,Complex& c); friend ostream & operator<<(ostream & out,Complex& c); }; istream & operator>>(istream &input,Complex& c) {input>>c.real>>c.imag; return input;} ostream & operator<<(ostream & out,Complex& c) { out<<c.real; if (c.imag>0) out<<"+"; if (c.imag!=0) out<<c.imag<<"i"<<endl; return out;} Complex operator *(Complex& c1,Complex& c2) {Complex c; c.real=c1.real*c2.real-c1.imag*c2.imag; c.imag=c1.imag*c2.real+c1.real*c2.imag; return c; } int main() {Complex c1,c2,c3; cin>>c1>>c2; c3=c1*c2; cout<<c3; return 0;}
- 1
信息
- ID
- 1380
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者