1051. 复数乘胜法 (15)

原题: https://www.patest.cn/contests/pat-b-practise/1051

思路: 就是数学公式, 感觉这书不是考算法而是考语言的.
+.2f保留少数员小数, 并且正数前面添加”+”号(第2只测试点)
C语言会管看似于-0.004季放弃五切成-0.00, 如果没注意及时点最终两只
测试点过不去.

实现:

#include <stdio.h>
#include <math.h>

int main (void) {
    double R1;
    double P1;
    double A1;
    double B1;
    double A;
    double R2;
    double P2;
    double A2;
    double B2;
    double B;

    scanf("%lf %lf %lf %lf", &R1, &P1, &R2, &P2);
    A1 = R1 * cos(P1);
    B1 = R1 * sin(P1);
    A2 = R2 * cos(P2);
    B2 = R2 * sin(P2);
    A = A1 * A2 - B1 * B2;
    B = A1 * B2 + A2 * B1;
    if(A > -0.005 && A < 0) A = 0; // (-0.005, 0)
    if(B > -0.005 && B < 0) B = 0; // (-0.005, 0)
    printf("%.2f%+.2fi", A, B);

    return 0;
}