新手水題,隻要注意題目要求:1.多項資料輸入。2.實數(即浮點數)。
這裡有精度要求(兩位小數),是以采用printf進行輸出(頭檔案是<cstdio>,c語言寫法<stdio.h>),公式就是兩點間距離公式,pow(a,b) ,就是a的b次方 ,sqrt(n) ,就是對n進行開方 ,這兩個是c語言數學函數,包含于<cmath>頭檔案(c語言應該寫<math.h>)。
HDU水題集合
以下是我的AC代碼:
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsISO2ETNwIDM5ETOyQDM3EDMy8CX0Vmbu4GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.jpg)
#include <cmath>
#include <cstdio>
using namespace std;
int main()
{
double x1,y1,x2,y2;
while(scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2)!=EOF)
printf("%.2f\n",sqrt(pow((x1-x2),2)+pow((y1-y2),2)));
return 0;
}