poj2365---求多边形边长总和

#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#define pi acos(-1)

struct point{
    double x,y;
}first,last,now;
double dist(struct point *a,struct point *b)
{
    return sqrt((a->x - b->x)*(a->x - b->x)+(a->y - b->y)*(a->y - b->y));
}

int main()
{
    int n,i;
    double ans=0.0,r;
    scanf("%d %lf",&n,&r);
    ans+=2*pi*r;
    scanf("%lf %lf",&first.x,&first.y);
    last=first;
    for(i=1;i<n;i++)
    {
        scanf("%lf %lf",&now.x,&now.y);
        ans+=dist(&last,&now);
        last=now;
    }
    ans+=dist(&first,&last);
    printf("%.2f
",ans);
    return 0;
}
View Code

用结构存储一个点的x,y坐标

结构指针(p)做参数,p->成员名

(*p).成员

在结构指针做参数的函数头部这样写:

double a(struct point *p1,struct point *p2)

struct point 相当于类型(int)

原文地址:https://www.cnblogs.com/gabygoole/p/4574120.html