1 条题解
-
0
C :
#include<stdio.h> #include<math.h> int main() { int n,i; int x1,y1,x2,y2; double h; while (scanf("%d",&n)!=EOF){ for (i=1;i<=n;i++){ scanf("%d%d%d%d",&x1,&y1,&x2,&y2); h=sqrt( ( ( x1-x2 )*( x1-x2 ) ) + ( (y1-y2)*(y1-y2) ) ); printf("%.2f\n",h); if (i==n){ break; } } } return 0; }
C++ :
#include <stdio.h> #include <math.h> class CPoint { int x,y; public: CPoint(int xx,int yy) { x=xx; y=yy; } double operator- (CPoint c); }; double CPoint::operator- (CPoint c) { return sqrt((x-c.x)*(x-c.x)+(y-c.y)*(y-c.y)); } int main() { //freopen("test.in", "r", stdin); //freopen("test.out", "w", stdout); int t; int ax, ay, bx, by; scanf("%d", &t); while (t--) { scanf("%d %d %d %d", &ax, &ay, &bx, &by); CPoint a(ax, ay), b(bx, by); printf("%.2f\n", a - b); } return 0; }
Java :
import java.text.DecimalFormat; import java.util.Scanner; public class Main { private static Scanner s = new Scanner (System.in) ; private static DecimalFormat df = new DecimalFormat("0.00") ; public static void main(String[] args) { int n = s.nextInt() ; for (int i = 0; i < n; i++) { int x1 = s.nextInt() ; int y1 = s.nextInt() ; int x2 = s.nextInt() ; int y2 = s.nextInt() ; System.out.println(df.format(Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)))) ; } } }
- 1
信息
- ID
- 1467
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者