
- 原题题目
- 代码实现
- 提交结果
原题题目
代码实现
#include
#include
using namespace std;
class Complex {
public:
Complex() : real_(0), imag_(0) {}
Complex(const double& real, const double& imag)
: real_(real), imag_(imag) {}
void input() {
cin >> real_ >> imag_;
}
operator double() { return sqrt(real_ * real_ + imag_ * imag_); }
Complex operator- (const Complex& other) {
return Complex(real_ - other.real_, imag_ - other.imag_);
}
private:
double real_;
double imag_;
};
template <typename T>
double dist(T a, T b) {
return b - a;
}
int main() {
int a1, b1;
double a2, b2;
Complex a3, b3;
int type;
cin >> type;
if (type == 1) {
cin >> a1 >> b1;
cout << dist(a1, b1) << endl;
}
else if (type == 2) {
cin >> a2 >> b2;
cout << dist(a2, b2) << endl;
}
else {
a3.input();
b3.input();
cout << dist(a3, b3) << endl;
}
return 0;
}
提交结果
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)