当前位置:网站首页>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;
}
边栏推荐
- Network security detection and prevention exercises (III)
- Idea common plug-ins
- Server journey from scratch - Yu Zhongxian integrated version (IP access server, LNMP compilation and installation, Lua environment and socket expansion)
- Network security detection and prevention test questions (II)
- System optimization method
- 请问通达信开户安全吗?
- 2.17(Avoid The Lakes)
- Tcp/ip test questions (I)
- 二、HikariCP獲取連接流程源碼分析二
- Redis cache preheating & avalanche & breakdown & penetration
猜你喜欢

Verification code native JS canvas

New features of php7

Jsonp processing non homologous

PostgreSQL user role permissions

Apifox simple understanding -- the integrator of web side testing

Miner's Diary: why should I go mining on April 5, 2021

ActiveMQ--CVE-2016-3088

Determine whether it is a web page opened on wechat

Huawei released two promotion plans to promote AI talent development and scientific research innovation

Connecting PHP to MySQL instances in the lamp environment of alicloud's liunx system
随机推荐
Google SEO external chain releases 50+ website platform sharing (e6zzseo)
Ali visual AI training camp -day05- creativity day - your image recognition project
Uniapp waterfall flow, applet waterfall flow, very simple, suitable for the whole platform
一、HikariCP获取连接流程源码分析一
Pdf file download (the download name is the same as the file name)
LNMP compilation and installation
PostgreSQL division considerations
Ali vision AI training camp-day01
Vulnhub range the planes: mercury
二、HikariCP獲取連接流程源碼分析二
Vulnhub range - darkhole 1
Yum command
Network security detection and prevention test questions (I)
ECS 7-day practical training camp (Advanced route) -- day01 -- setting up FTP service based on ECS
Can the stock account opened through qiniu school be used? Is the fund safe?
Solidity date tool
PHP little knowledge record
From now on, I will blog my code
1、 Hikaricp source code analysis of connection acquisition process I
Android Development Notes - Quick Start (from sqllite to room licentiousness) 2