当前位置:网站首页>Electronic Society C language level 1 31. Calculate line segment length
Electronic Society C language level 1 31. Calculate line segment length
2022-06-26 22:46:00 【dllglvzhenfeng】
Electronics Association C Language 1 level 31 、 Calculate the line length
OpenJudge - 16: Calculate the line length
C++ Method 1 :
/*
Electronics Association C Language 1 level 31 、 Calculate the line length
http://noi.openjudge.cn/ch0103/16/
The coordinates of the two endpoints of a given line segment A(Xa,Ya),B(Xb,Yb), Find line segment AB The length of .
There are two lines of input .
The first line is two real numbers Xa,Ya, namely A Coordinates of .
The second line is two real numbers Xb,Yb, namely B Coordinates of .
The absolute value of all real numbers in the input does not exceed 10000.
Output
A real number , That's line segments AB The length of , Keep it after the decimal point 3 position .
The sample input
1 1
2 2
Sample output
1.414
The coordinates of the two endpoints of a given line segment A(Xa,Ya),B(Xb,Yb), Find line segment AB The length of .
http://noi.openjudge.cn/ch0103/16/
*/
#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
double xa,xb,ya,yb,len;
cin>>xa>>ya;
cin>>xb>>yb;
len=sqrt( pow(xa-xb,2)+pow(ya-yb,2) );
//len=sqrt(pow(2,xa-xb) +pow(2,ya-yb));
//sqrt( ) Square root function pow( ) power function
printf("%0.3f",len);
return 0;
}C++ Method 2 :
/* Electronics Association C Language 1 level 31 、 Calculate the line length Method 2 http://noi.openjudge.cn/ch0103/16/ */ #include <iostream> #include <iomanip> #include <cmath> using namespace std; int main() { double Xa, Ya, Xb, Yb; cin >> Xa >> Ya >> Xb >> Yb; double ans; //ans=sqrt(pow((Xa-Xb),2)+pow((Ya-Yb),2)); ans=sqrt( (Xa-Xb)*(Xa-Xb) + (Ya-Yb)*(Ya-Yb) ); cout << fixed << setprecision(3) <<ans ; return 0; }
C++ Method 3 :
/*
Electronics Association C Language 1 level 31 、 Calculate the line length Method 3
http://noi.openjudge.cn/ch0103/16/
*/
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main()
{
double a,b,c,d;
cin>>a>>b;
cin>>c>>d;
printf("%.3f\n",sqrt((a-c)*(a-c)+(b-d)*(b-d)));
//printf("%.3f\n",sqrt((a-c)*(a-c)+(b-d)*(b-d)));
return 0;
}C++ Method four :
/*
Electronics Association C Language 1 level 31 、 Calculate the line length Method four
http://noi.openjudge.cn/ch0103/16/
*/
#include <math.h>
#include <stdlib.h>
int main()
{
double Xa,Ya,Xb,Yb;
double l;
scanf("%lf%lf%lf%lf",&Xa,&Ya,&Xb,&Yb);
l=sqrt((Xb-Xa)*(Xb-Xa)+(Yb-Ya)*(Yb-Ya));
printf("%.3lf\n",l);
system("pause");
return 0;
}C++ Method five :
/*
Electronics Association C Language 1 level 31 、 Calculate the line length Method five
http://noi.openjudge.cn/ch0103/16/
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
float xa,ya,xb,yb;
scanf("%f%f%f%f",&xa,&ya,&xb,&yb);
printf("%.3f\n",sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb)));
system("pause");
return 0;
}python3 Code :
"""
1.3 Arithmetic expression and sequential execution of programming basis 16 Calculate the line length
http://noi.openjudge.cn/ch0103/16/
https://blog.csdn.net/weixin_45852964/article/details/103090884
"""
import math
xa,ya=map(float,input().split())
xb,yb=map(float,input().split())
l=math.sqrt((yb-ya)*(yb-ya)+(xb-xa)*(xb-xa))
print("%.3f"%l)Electronics Association Youth software programming level test C Language over the years
Electronics Association C Language Real and simulated questions
Electronics Association C Language 1 level 5 、 Judge whether it can be 3 ,5 ,7 to be divisible by
Electronics Association C Language 1 level 6 、 Cycling and walking
Electronics Association C Language 1 level 7 、 Draw a rectangular
Electronics Association C Language 1 level 18 、 Calculate postage
Electronics Association C Language 1 level 19 、 Find the sum and mean of integers
Electronics Association C Language 1 level 21 、 The problem of logical judgment Enter three numbers a,b,c, The largest output
Electronics Association C Language 1 level 23 、 Judge the average leap year
Electronics Association C Language 1 level 24 、 Find the greatest common divisor
Electronics Association C Language 1 level 28 、 Character diamond
Electronics Association C Language 1 level 29 、 Align output
Electronics Association C Language 1 level 29 、 Align output
Electronics Association C Language 1 level 29 、 Align output _dllglvzhenfeng The blog of -CSDN Blog
Electronic Society junior programming grade test
边栏推荐
- The sharp sword of API management -- eolink
- Introduction de l'opérateur
- DAST 黑盒漏洞扫描器 第五篇:漏洞扫描引擎与服务能力
- Leetcode - the best time to buy or sell stocks
- Common configuration of jupyterlab
- Unity: 脚本缺失 “The referenced script (Unknown) on this Behaviour is missing!“
- 分享三种在Excel表格中自动求和的方法
- 数据治理啥都干
- Release of dolphin scheduler video tutorial in Shangsi Valley
- What are the test case design methods?
猜你喜欢
![leetcode:710. Random numbers in the blacklist [mapping thinking]](/img/ec/a3faeae6636bc3d0d9536962fdd9af.png)
leetcode:710. Random numbers in the blacklist [mapping thinking]
![Selenium电脑上怎么下载-Selenium下载和安装图文教程[超详细]](/img/ec/1c324dcf38d07742a139aac2bab02e.png)
Selenium电脑上怎么下载-Selenium下载和安装图文教程[超详细]

Leetcode (763) -- dividing letter ranges
![leetcode:141. Circular linked list [hash table + speed pointer]](/img/19/f918f2cff9f831d4bbc411fe1b9776.png)
leetcode:141. Circular linked list [hash table + speed pointer]

leetcode:141. 环形链表【哈希表 + 快慢指针】

vulnhub之DC9

Configuring assimp Library in QT environment (MinGW compiler)

Pass note 【 dynamic planning 】

从位图到布隆过滤器,C#实现

Three solutions for improving embedded software development environment
随机推荐
Unity cloth system_ Cloth component (including dynamic call related)
开放世界机甲游戏-Phantom Galaxies
VB. Net class library to obtain the color under the mouse in the screen (Advanced - 3)
【混合编程jni 】第十二篇 jnaerator
leetcode - 买卖股票的最佳时机
Configuring assimp Library in QT environment (MinGW compiler)
买股票通过中金证券经理的开户二维码开户资金是否安全?想开户炒股
Release of dolphin scheduler video tutorial in Shangsi Valley
數據清洗工具flashtext,效率直接提昇了幾十倍數
Unity3d plug-in anyportrait 2D bone animation
Centos7编译安装Redis
【BUG反馈】WebIM在线聊天系统发消息时间问题
美术向的Unity动画知识
VB. Net class library (Advanced - 2 overload)
Some ways out for older programmers
【老卫搞机】090期:键盘?主机?全功能键盘主机!
[mixed programming JNI] Part 7: JNI command lines
Brief analysis of the self inspection contents of the blue team in the attack and defense drill
Leetcode (122) - the best time to buy and sell stocks II
What is the “ How to remove a custom form list?