Division of Nlogonia

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2493 判断输入坐标在哪个方位,建立坐标系,关键是与 坐标原点比较

#include<stdio.h>

int main(){

    int h,z,t,a,b;

    while(scanf("%d",&t)!=EOF){

    if(t==0)break;

     scanf("%d%d",&a,&b);

              while(t--){

    scanf("%d%d",&h,&z);

            if(h<a&&z>b) printf("NO\n");

    else if(h>a&&z>b)printf("NE\n");

    else if(h>a&&z<b)printf("SE\n");

    else if(h<a&&z<b)printf("SO\n");

    else printf("divisa\n");

    } }

    return 0;

}

转载于:https://www.cnblogs.com/sujunjie/archive/2013/02/28/2937580.html

To define the addition, subtraction, multiplication, and division operators of complex numbers, we need to first understand the basic arithmetic operations on complex numbers. Addition: (a+bi) + (c+di) = (a+c) + (b+d)i Subtraction: (a+bi) - (c+di) = (a-c) + (b-d)i Multiplication: (a+bi) * (c+di) = (ac-bd) + (ad+bc)i Division: (a+bi) / (c+di) = ((ac+bd)/(c^2 + d^2)) + ((bc-ad)/(c^2 + d^2))i To implement these operations in a program, we can define a class for complex numbers and overload the operators using operator overloading. Here's an example program that implements the required functions: ``` #include <iostream> using namespace std; class Complex { private: double real, imag; public: Complex(double r = 0, double i = 0) : real(r), imag(i) {} // Addition operator overloading Complex operator+(const Complex& c) const { return Complex(real + c.real, imag + c.imag); } // Subtraction operator overloading Complex operator-(const Complex& c) const { return Complex(real - c.real, imag - c.imag); } // Multiplication operator overloading Complex operator*(const Complex& c) const { return Complex(real * c.real - imag * c.imag, real * c.imag + imag * c.real); } // Division operator overloading Complex operator/(const Complex& c) const { double den = c.real * c.real + c.imag * c.imag; return Complex((real * c.real + imag * c.imag) / den, (imag * c.real - real * c.imag) / den); } // Addition operator overloading with integer Complex operator+(const int num) const { return Complex(real + num, imag); } // Subtraction operator overloading with integer Complex operator-(const int num) const { return Complex(real - num, imag); } // Multiplication operator overloading with integer Complex operator*(const int num) const { return Complex(real * num, imag * num); } // Division operator overloading with integer Complex operator/(const int num) const { return Complex(real / num, imag / num); } // Output operator overloading friend ostream& operator<<(ostream& os, const Complex& c) { os << c.real << (c.imag >= 0 ? "+" : "") << c.imag << "i"; return os; } }; int main() { Complex c1(1, 2), c2(3, 4); int num = 5; // Addition, subtraction, multiplication, and division of two complex numbers cout << "c1 + c2 = " << c1 + c2 << endl; cout << "c1 - c2 = " << c1 - c2 << endl; cout << "c1 * c2 = " << c1 * c2 << endl; cout << "c1 / c2 = " << c1 / c2 << endl; // Addition, subtraction, multiplication, and division of complex number c1 and integer num cout << "c1 + num = " << c1 + num << endl; cout << "c1 - num = " << c1 - num << endl; cout << "c1 * num = " << c1 * num << endl; cout << "c1 / num = " << c1 / num << endl; // Addition, subtraction, multiplication, and division of integer num and complex number c1 cout << "num + c1 = " << num + c1 << endl; cout << "num - c1 = " << num - c1 << endl; cout << "num * c1 = " << num * c1 << endl; cout << "num / c1 = " << num / c1 << endl; return 0; } ``` Input format and output format are the same as mentioned in the problem statement.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值