当前位置:网站首页>电子协会 C语言 1级 31 、 计算线段长度
电子协会 C语言 1级 31 、 计算线段长度
2022-06-26 22:40:00 【dllglvzhenfeng】
电子协会 C语言 1级 31 、 计算线段长度
C++ 方法一:
/*
电子协会 C语言 1级 31 、 计算线段长度
http://noi.openjudge.cn/ch0103/16/
已知线段的两个端点的坐标 A(Xa,Ya),B(Xb,Yb),求线段 AB 的长度。
输入共两行。
第一行是两个实数 Xa,Ya,即 A 的坐标。
第二行是两个实数 Xb,Yb,即 B 的坐标。
输入中所有实数的绝对值均不超过 10000。
输出
一个实数,即线段 AB 的长度,保留到小数点后 3 位。
样例输入
1 1
2 2
样例输出
1.414
已知线段的两个端点的坐标 A(Xa,Ya),B(Xb,Yb),求线段 AB 的长度。
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( )开平方函数 pow( )幂函数
printf("%0.3f",len);
return 0;
}C++方法二:
/* 电子协会 C语言 1级 31 、 计算线段长度 方法二 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++方法三:
/*
电子协会 C语言 1级 31 、 计算线段长度 方法三
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++方法四:
/*
电子协会 C语言 1级 31 、 计算线段长度 方法四
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++ 方法五:
/*
电子协会 C语言 1级 31 、 计算线段长度 方法五
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代码:
"""
1.3编程基础之算术表达式与顺序执行 16 计算线段长度
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)电子协会 青少年软件编程等级考试 C语言历年真题
电子协会 青少年软件编程等级考试 C语言历年真题_dllglvzhenfeng的博客-CSDN博客
电子协会C语言 真题与模拟题
电子协会C语言 真题与模拟题_dllglvzhenfeng的博客-CSDN博客
电子协会 C语言 1级 5 、判断能否被 3 ,5 ,7 整除
电子协会 C语言 1级 5 、判断能否被 3 ,5 ,7 整除_dllglvzhenfeng的博客-CSDN博客
电子协会 C语言 1级 6 、骑车与走路
电子协会 C语言 1级 6 、骑车与走路_dllglvzhenfeng的博客-CSDN博客
电子协会 C语言 1级 7 、画矩形
电子协会 C语言 1级 7 、画矩形_dllglvzhenfeng的博客-CSDN博客
电子协会 C语言 1级 18 、计算邮资
电子协会 C语言 1级 18 、计算邮资_dllglvzhenfeng的博客-CSDN博客_csp试题
电子协会 C语言 1级 19 、求整数的和与均值
电子协会 C语言 1级 19 、求整数的和与均值_dllglvzhenfeng的博客-CSDN博客_电子学会c语言一级
电子协会 C语言 1级 21 、逻辑判断问题 输入三个数 a,b,c,输出最大者
电子协会 C语言 1级 21 、逻辑判断问题 输入三个数 a,b,c,输出最大者_dllglvzhenfeng的博客-CSDN博客
电子协会 C语言 1级 23 、判断平闰年
电子协会 C语言 1级 23 、判断平闰年_dllglvzhenfeng的博客-CSDN博客
电子协会 C语言 1级 24 、求最大公约数
电子协会 C语言 1级 24 、求最大公约数_dllglvzhenfeng的博客-CSDN博客
电子协会 C语言 1级 28 、字符菱形
电子协会 C语言 1级 28 、字符菱形_dllglvzhenfeng的博客-CSDN博客
电子协会 C语言 1级 29 、对齐输出
电子协会 C语言 1级 29 、对齐输出
电子协会 C语言 1级 29 、 对齐输出_dllglvzhenfeng的博客-CSDN博客
电子学会青少年编程等级考试
边栏推荐
- leetcode:141. 环形链表【哈希表 + 快慢指针】
- leetcode:6103. Delete the minimum score of the edge from the tree [DFS + connected component + value record of the subgraph]
- Système de distribution Unity Composants en tissu (y compris les dépendances d'appel dynamique)
- Wechat applet is authorized to log in wx getUserProfile
- Test comparison of linear model LN, single neural network SNN, deep neural network DNN and CNN
- Partage de trois méthodes de sommation automatique dans un tableau Excel
- Leetcode (122) - the best time to buy and sell stocks II
- Detailed explanation of nmap parameters
- Data governance does everything
- Unity3D插件 AnyPortrait 2D骨骼动画制作
猜你喜欢

L'outil de nettoyage des données flashtext améliore directement l'efficacité de plusieurs dizaines de fois

Leetcode (763) -- dividing letter ranges
![[machine learning] - Introduction to vernacular and explanation of terms](/img/4c/e18fe52a71444c2ca08167ead9f28f.jpg)
[machine learning] - Introduction to vernacular and explanation of terms

Test comparison of linear model LN, single neural network SNN, deep neural network DNN and CNN
![leetcode:6103. Delete the minimum score of the edge from the tree [DFS + connected component + value record of the subgraph]](/img/16/8dc63e6494b3f23e2685e287abc94c.png)
leetcode:6103. Delete the minimum score of the edge from the tree [DFS + connected component + value record of the subgraph]

leetcode:152. 乘积最大子数组【考虑两个维度的dp】
![leetcode:710. Random numbers in the blacklist [mapping thinking]](/img/ec/a3faeae6636bc3d0d9536962fdd9af.png)
leetcode:710. Random numbers in the blacklist [mapping thinking]

leetcode:6103. 从树中删除边的最小分数【dfs + 联通分量 + 子图的值记录】

AI intelligent matting tool - hair can be seen

MATLAB and MySQL database connection and data exchange (based on ODBC)
随机推荐
leetcode:6107. 不同骰子序列的数目【dp六个状态 + dfs记忆化】
同花顺注册开户有没有什么风险?安全吗?
curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection
[fundamentals of image processing] GUI image histogram equalization system based on MATLAB [including Matlab source code 1924]
Leetcode (763) -- dividing letter ranges
數據清洗工具flashtext,效率直接提昇了幾十倍數
[kotlin] keyword suspend learning of thread operation and async understanding
Introduction to operator
Unity method for setting material and shader
BS-GX-016基于SSM实现教材管理系统
Restfultoolkitx of idea utility plug-in -- restful interface debugging
Unity cloth system_ Cloth component (including dynamic call related)
Product design in the extreme Internet Era
VB. Net class library (advanced version - 1)
CVPR 2022 | 美团技术团队精选论文解读
VB. Net class library - 4 screen shots, clipping
MacOS环境下使用HomeBrew安装[email protected]
在哪家券商公司开户最方便最安全可靠
Web crawler 2: crawl the user ID and home page address of Netease cloud music reviews
简析攻防演练中蓝队的自查内容