二次元平面上に 2 つの点 (xs, ys), (xt, yt) がある。両者の間の距離を求めよ。ただし、距離はユークリッド距離で測るとする。
入力の 1 行目に 2 つの数 xs, ys が 1 つの空白文字で区切られて与えられる。2 行目も同様に、2 つの数 xt, yt が 1 つの空白文字で区切られて与えられる。
与えられる数はすべて 0 以上 100 以下の実数である。
2 点間の距離を、小数点以下 6 桁目を四捨五入することにより 5 桁目まで出力せよ。答えは10-5までの絶対誤差が許容される。
0 0 3 4
0.0 0.0 100.0 100.0
10 10 10 10.0
5.00000
141.42136
0.00000
#include <stdio.h>
#include <math.h>
int main(void) {
double x1, y1, x2, y2;
double s;
scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
s = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
printf("%.5f\n", s);
return 0;
}
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
double x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
double s = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
cout << fixed << setprecision(5) << s << endl;
return 0;
}
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double x1 = sc.nextDouble();
double y1 = sc.nextDouble();
double x2 = sc.nextDouble();
double y2 = sc.nextDouble();
double s = Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
System.out.printf("%.5f\n", s);
}
}