zoukankan      html  css  js  c++  java
  • hdu 2001 计算两点的距离

    hdu 2001 计算两点的距离

    link

    题目描述

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 272428 Accepted Submission(s): 94255

    Problem Description
    输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。

    Input
    输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开。

    Output
    对于每组输入数据,输出一行,结果保留两位小数。

    Sample Input
    0 0 0 1
    0 1 1 0

    Sample Output
    1.00
    1.41

    Author
    lcy

    问题解答

    #include <stdio.h>
    #include <math.h>
    
    int main(void)
    {
        float x1=0,y1=0,x2=0,y2=0,d;
        for(int i=1;scanf("%f%f%f%f",&x1,&y1,&x2,&y2)!=EOF;i++)
        {
        d=sqrt(pow((x1-x2),2)+pow((y1-y2),2));
        printf("%-4.2f
    ",d);
        }
    }
    

    笔记

    1. 第6行,要注意数据定义类型(float)。
    2. 第10行,精度表达形式:“-”号代表左对齐(如果没有负号,默认右对齐),“4”代表输出数据有4个宽度(包括小数点在内),“2”表示数据有两位小数(以“%f”格式输出时,默认的小数位是6位)。
  • 相关阅读:
    leetcode211
    leetcode209
    leetcode201
    leetcode1396
    leetcode1395
    leetcode1394
    leetcode1386
    leetcode1387
    leetcode1382
    leetcode1376
  • 原文地址:https://www.cnblogs.com/yuzilan/p/10626228.html
Copyright © 2011-2022 走看看