当前位置:网站首页>PTA: spacing of 7-69 data
PTA: spacing of 7-69 data
2022-06-23 04:26:00 【Sy_ Faker】
Plural Complex There are two data members :a and b, Represent the real part and imaginary part of a complex number respectively , There are several constructors and an overload -( minus sign , Used to calculate the distance between two complex numbers ) Member function of . It is required to design a function template
template < class T >
double dist(T a, T b)
Yes int,float,Complex Or other types of data , Returns the spacing between two data .
The above class name and function template form , Must be in accordance with the requirements of the topic , Do not modify
Input format :
Each action is an operation , The first number in each line is the element type ,1 Is an integer element ,2 Is a floating point element ,3 by Complex type , If integer element , Then enter two integer data , If it is a floating-point element , Then enter two floating-point data , if Complex Type element , Enter two Complex Type data (a1 b1 a2 b2), Input 0 Mark the end of input .
Output format :
For each input , Output one spacing value per line .
sample input :
1 2 5
3 2 4 5 9
2 2.2 9.9
0
sample output :
3
5.83095
7.7
#include<iostream>
#include<cmath>
using namespace std;
class Complex
{
int a;
int b;
public:
Complex()
{
a=0;
b=0;
}
Complex(int x,int y)
{
a=x;
b=y;
}
float operator -(Complex&c)
{
return (sqrt((a-c.a)*(a-c.a)+(b-c.b)*(b-c.b)));
}
};
template<class T>
double dist(T a,T b)
{
return fabs(a-b);
}
int main()
{
int type;
cin>>type;
int i1,i2;
float f1,f2;
int x1,x2,y1,y2;
while(type!=0)
{
switch(type)
{
case 1:
cin>>i1>>i2;
cout<<dist(i1,i2)<<endl;
break;
case 2:
cin>>f1>>f2;
cout<<dist(f1,f2)<<endl;
break;
case 3:
cin>>x1>>y1>>x2>>y2;
Complex c1(x1,y1),c2(x2,y2);
cout<<c1-c2<<endl;
break;
}
cin>>type;
}
}
边栏推荐
- Form development mode
- Pyspark, paid for data cleaning and uploading to the database
- [tcapulusdb knowledge base] [list table] example code for replacing the data at the specified location in the list
- 背景彩带动画插件ribbon.js
- 虫子 STM32 中断 (懂的都懂)
- mysql,字段问题
- Why APP But Not WebPage
- 在线JSON转CSharp(C#)Class工具
- photoshop PS 查看像素坐标、像素颜色、像素HSB颜色
- Similar to RZ / SZ, trzsz supporting TMUX has released a new version
猜你喜欢
随机推荐
【二叉樹進階】AVLTree - 平衡二叉搜索樹
【二叉树进阶】AVLTree - 平衡二叉搜索树
How to realize data transaction
Tables de recherche statiques et tables de recherche statiques
华为联机对战服务玩家快速匹配后,不同玩家收到的同一房间内玩家列表不同
Twitter与Shopify合作 将商家产品引入Twitter购物当中
PTA:7-87 集合的模拟实现(类模板)
What if the self incrementing IDs of online MySQL are exhausted?
[Zeng shuge's laser slam notes] gmapping filter based slam
在 KubeSphere 上部署 Apache Pulsar
APM 工具 SkyWalking 是什么
SVG+JS智能家居监控网格布局
【LeetCode】23. Merge K ascending linked lists
1-1 introduction to VMWare
AI video cloud: a good wife in the era of we media
photoshop PS 查看像素坐标、像素颜色、像素HSB颜色
Source code encryption of data encryption technology
Adobe international certification 𞓜 how IIT Madras brings efficiency and accessibility to scholars through Adobe e Acrobat
[tcapulusdb knowledge base] [list table] example code for replacing the data at the specified location in the list
支持在 Kubernetes 运行,添加多种连接器,SeaTunnel 2.1.2 版本正式发布!









