View Code of Problem 15

#include<stdio.h>
#include<math.h>
double x[100],y[100];
int main()
{
	int n;
	int time=0;
	while(scanf("%d",&n)!=EOF,n!=0)
	{
		int j;
		int m;
		double s=0;
		for(j=0;j<=n;j++)
		{
		scanf("%d",&m);
		if(m==0) break;
        int i;
		for(i=1;i<=m;i++)
			scanf("%lf%lf",&x[i],&y[i]);
		double sum=0;
        for(i=2;i<m;i++)
		{
			sum=sum+fabs((x[i]-x[1])*(y[i+1]-y[1]))+fabs((x[i+1]-x[1])*(y[i]-y[1]));
		}
		s+=sum;
		}
		printf("Case #%d: ",++time);
		printf("%.4f\n",s/2);
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 15