当前位置:网站首页>PAT B1051
PAT B1051
2022-06-25 19:56:00 【Madness makes freedom】
1051 Complex multiplication (15 branch )
The plural can be written as (A+Bi) The normal form of , among A It's the real part ,B It's the empty part ,i Imaginary units , Satisfy i2=−1; It can also be written as an exponential form in polar coordinates (R×e(Pi)), among R It's a complex module ,P It's the angle ,i Imaginary units , It's equivalent to the trigonometric form R(cos(P)+isin(P)).
Now let's give two complex numbers R and P, The normal form of the product of two numbers is required .
Input format :
Enter two complex numbers in a row R1, P1, R2, P2, Numbers are separated by spaces .
Output format :
In a row, press A+Bi The normal form of the product of two numbers , Both the real part and the virtual part are reserved 2 Decimal place . Be careful : If B It's a negative number , It should be written as A-|B|i In the form of .
sample input :
2.3 3.5 5.2 0.4
sample output :
-8.68-8.23iFor the result 0 When , To make a special judgment , Because a very small decimal is rounded to the nearest 0 When , It could be a positive number , It can also be negative , When it's negative , We can't output this minus sign !!!!
Regarding this , I wrote two codes !
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
double r1,p1,r2,p2;
cin >> r1 >> p1 >> r2 >> p2;
double r=r1*r2,p=p1+p2;
double x=r*cos(p),y=r*sin(p);
if(x+0.005>0&&x<0)
printf("0.00");
else
printf("%.2f",x);
if(y+0.005>0&&y<0)
printf("+0.00i");
else if(y<0)
printf("-%.2fi\n",fabs(y));
else
printf("+%.2fi\n",y);
return 0;
}
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
double r1,p1,r2,p2;
cin >> r1 >> p1 >> r2 >> p2;
double x1=r1*cos(p1),y1=r1*sin(p1),x2=r2*cos(p2),y2=r2*sin(p2);
double x=x1*x2-y1*y2,y=x1*y2+x2*y1;
if(x+0.005>0&&x<0)
printf("0.00");
else
printf("%.2f",x);
if(y+0.005>0&&y<0)
printf("+0.00i\n");
else if(y<0)
printf("-%.2fi\n",fabs(y));
else
printf("+%.2fi\n",y);
return 0;
}
边栏推荐
- Solve the problem that sublime Text3 package control cannot install plug-ins
- Jsonp processing non homologous
- MySQL prompt performance_ Schema missing table
- JS get the parameters in the URL link
- Tcp/ip test questions (III)
- Embark on a new journey and reach the world with wisdom
- Server journey from scratch - Yu Zhongxian integrated version (IP access server, LNMP compilation and installation, Lua environment and socket expansion)
- PostgreSQL user role permissions
- SEO outsourcing reliable company, enterprise SEO outsourcing company which reliable?
- DARKHOLE 2
猜你喜欢

Jsonp non homologous interaction (click trigger)

Can GoogleSEO only do content without external chain? (e6zzseo)

PostgreSQL user role permissions

Wechat applet cloud function does not have dependency option installed

Profile path and name

PHP synchronizes website content to hundreds of websites to improve SEO ranking

Ali visual AI training camp -day03- construction of electronic photo album (face and expression recognition)

What are Baidu collection skills? 2022 Baidu article collection skills

Wechat applet connects to the server to display mqtt data information

New features of php7
随机推荐
Hdoj topic 2005 day
Is it safe to open an account with flush?
Convert word to PDF through libreoffice
Bindgetuserinfo will not pop up
1、 Hikaricp source code analysis of connection acquisition process I
Use of serialize() and serializearray() methods for form data serialization
通过启牛学堂开的股票账户可以用吗?资金安全吗?
Two types of attribute injection methods
JQ implements tab switching
一、HikariCP获取连接流程源码分析一
Network security detection and prevention test questions (II)
DARKHOLE 2
Apifox simple understanding -- the integrator of web side testing
Arduino ide + esp8266+mqtt subscribe to publish temperature and humidity information
Principles of MySQL clustered index and non clustered index
Automatic fitting when the applet reaches the top
Wechat applet swiper simple local picture display appears large blank
Force wechat page font size to be 100%
Mail monitoring cloud script execution progress
Jsonp non homologous interaction (click trigger)