#include #include #include #include int sortXY(const void * _a, const void * _b) { int *a = (int*)_a; int *b = (int*)_b; if(a[0] < b[0]) return -1; else if (a[0] > b[0]) return 1; else return a[1] - b[1]; } int sortYX(const void *_a, const void *_b) { int *a = (int*)_a; int *b = (int*)_b; if(a[1] < b[1]) return -1; else if (a[1] > b[1]) return 1; else return a[0] - b[0]; } int secti(int (*posts)[2], int P, int C) { int F; for (F = 0; P--; P--) F += posts[P][C] - posts[P - 1][C]; return F; } int main() { int posts[100000][2]; int P; int F; int N; scanf("%d", &P); while (P) { N = P; while (P--) scanf("%d %d", posts[P], posts[P] + 1); F = 0; qsort(posts, N, 2*sizeof(int), sortYX); F += secti(posts, N, 0); qsort(posts, N, 2*sizeof(int), sortXY); F += secti(posts, N, 1); printf("The length of the fence will be %d units.\n", F); scanf("%d\n", &P); } return 0; }