题目链接:1051 复数乘法
思路
被后面2个测试点卡了半天,查了一圈其他大佬这么说的才知道浮点数保留两位小数,意味着“截断”,截断就有可能出现 - 0.00的情况。而截断的话-0.003会变成-0.00而不是+0.00。
代码
#include <iostream>
#include <math.h>
using namespace std
;
int main(){
double R1
,P1
,R2
,P2
,A
,B
;
cin
>> R1
>> P1
>> R2
>> P2
;
A
= R1
* R2
* (cos(P1
+ P2
));
B
= R1
* R2
* (sin(P1
+ P2
));
if(A
< 0 && A
> -0.005) A
= 0;
if(B
< 0 && B
> -0.005) B
= 0;
if(B
>= 0)printf("%.2f+%.2fi",A
,B
);
else printf("%.2f%.2fi",A
,B
);
return 0;
}
转载请注明原文地址:https://blackberry.8miu.com/read-18038.html