首页 > 代码库 > 算法训练 P1103

算法训练 P1103

水,注意好输入输出就可以

#include <iostream>
#include <iomanip>

using namespace std;

void jia(double x,double y,double z,double w)
{
        cout<<fixed<<setprecision(2)<<x+z<<+<<y+w<<i<<endl;
}
void jian(double x,double y,double z,double w)
{
        cout<<fixed<<setprecision(2)<<x-z<<+<<y-w<<i<<endl;
}
void cheng(double x,double y,double z,double w)
{
        cout<<fixed<<setprecision(2)<<x*z-y*w<<+<<y*z+x*w<<i<<endl;
}
void chu(double x,double y,double z,double w)
{
        cout<<fixed<<setprecision(2)<<(x*z+y*w)/(z*z+w*w)<<+<<(y*z-x*w)/(z*z+w*w)<<i<<endl;
}

int main()
{
    char a;
    double x,y,z,w;

    while(cin>>a>>x>>y>>z>>w)
    {
            if(a==+)
                jia(x,y,z,w);
            else if(a==-)
                jian(x,y,z,w);
            else if(a==*)
                cheng(x,y,z,w);
            else if(a==/)
                chu(x,y,z,w);
    }

    return 0;
}

 

算法训练 P1103