• 算法训练 P1103


    #include <cstdio>
    #include <iostream>
    
    using namespace std;
    
    struct num{
        double a;
        double b;
    };
    void add(struct num A, struct num B, struct num* C);
    void sub(struct num A, struct num B, struct num* C);
    void mul(struct num A, struct num B, struct num* C);
    void div(struct num A, struct num B, struct num* C);
    void clac(char op, struct num A, struct num B, struct num* C);
    
    void clac(char op, struct num A, struct num B, struct num* C){
    
        switch(op){
            case '+': add(A,B,C); break;
            case '-': sub(A,B,C); break;
            case '*': mul(A,B,C); break;
            case '/': div(A,B,C); break;
        }
    }
    
    void add(struct num A, struct num B, struct num* C){
        C->a = A.a + B.a;
        C->b = A.b + B.b;
    }
    
    void sub(struct num A, struct num B, struct num* C){
        C->a = A.a - B.a;
        C->b = A.b - B.b;
    }
    
    void mul(struct num A, struct num B, struct num* C){
        C->a = A.a*B.a - A.b*B.b;
        C->b = A.a*B.b + A.b*B.a;
    }
    
    void div(struct num A, struct num B, struct num* C){
        double x = B.a*B.a + B.b*B.b;
        C->a = (A.a*B.a + A.b*B.b)/x;
        C->b = (A.b*B.a - A.a*B.b)/x;
    }
    
    int main(){
        struct num A;
        struct num B;
        struct num C;
        char op;
        cin >> op >> A.a >> A.b >> B.a >> B.b;
        clac(op, A,B,&C);
        printf("%.2f+%.2fi
    ", C.a, C.b);
    
        return 0;
    }
  • 相关阅读:
    VuGen错误处理函数
    LR的日志
    创建性能测试脚本时如何选择HTML模式和URL模式
    Java变量
    查找&排序
    selenium执行JS
    Python中 is 和 == 的区别
    Python中 and or的计算规则
    selenium使用location定位元素坐标偏差
    错误:Could not find an available JavaScript runtime
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12538130.html
Copyright © 2020-2023  润新知