题目传送门:2711. 模板与STL
代码:
1 #include <iostream> 2 #include <vector> 3 #include <algorithm> 4 using namespace std; 5 6 7 class Complex{ 8 private: 9 int real; 10 int imagine; 11 public: 12 Complex(int r = 0,int i = 0){ 13 real = r; 14 imagine = i; 15 } 16 friend ostream & operator <<(ostream &dout,const Complex &c){ 17 dout << ‘(‘ << c.real << ‘,‘ << c.imagine << ‘)‘ << endl; 18 return dout; 19 } 20 void set_real(int r){ 21 real = r; 22 } 23 void set_imagine(int i){ 24 imagine = i; 25 } 26 int get_real(){ 27 return real; 28 } 29 int get_imagine(){ 30 return imagine; 31 } 32 };