/* Solution: If the Shoe Fits */
/* E. Jason Riedy, ejr@cise.ufl.edu */
/*
  This problem is much simpler than it appears.  Only the uppermost
  point of each toe must be checked.  If the ellipse that is the
  shoe intersects a toe, it intersects on both sides of this point.
*/

#include<stdlib.h>
#include<stdio.h>

void main(void)
{
  float height[5], width[5];
  float center[5], tmp;
  int num_lost, outside[5];
  float shoe_extent, shoe_width;

  int i;
  float x, y, ell;

  for (i = 0; i < 5; i++) {
    printf("Height and width of toe #%d: ", i+1);
    scanf("%g %g", &height[i], &width[i]);
  }

  printf("Extent and width of the shoe's toe: ");
  scanf("%g %g", &shoe_extent, &shoe_width);

  /* Normalize the X coordinates... */
  tmp = width[0];
  center[0] = width[0]/2.0;
  for (i = 1; i < 5; i++) {
    tmp += width[i];
    center[i] = center[i-1] + width[i-1]/2.0 + width[i]/2.0;
  }
  tmp /= 2.0;
  for (i = 0; i < 5; i++)
    center[i] = center[i] - tmp;
  
  /* Now check if each (center[i], height[i]) is within the ellipse.  */
  for (num_lost = i = 0; i < 5; i++) {
    x = center[i];
    y = height[i];
    ell = (x/(shoe_width/2.0)) * (x/(shoe_width/2.0))
          + (y/shoe_extent) * (y/shoe_extent) 
          - 1;
    outside[i] = (ell > 0? 1 : 0);
    num_lost += outside[i];
  }
  

  /* Unnecessarily complex output... */
  if (0 == num_lost) {
    printf("This sister loses no toes.  So much for Cinderella.\n");
  }
  else if (1 == num_lost) {
    printf("This sister loses toe ");
    for (i = 0; !outside[i]; i++);
    printf("%d.\n", i+1);
  }
  else if (2 == num_lost) {
    printf("This sister loses toes ");
    for (i = 0; !outside[i]; i++);
    printf("%d and ", i+1);
    for (i++;!outside[i]; i++);
    printf("%d.\n", i+1);
  }
  else {
    printf("This sister loses toes ");
    for (i = 0; num_lost > 1; i++)
      if (outside[i]) {
	printf("%d, ", i+1);
	num_lost--;
      }
    for (; !outside[i]; i++);
    printf("and %d.\n", i+1);
  }
  
}

