/* Mat Fishers program for reading and sorting dates */

#include <stdio.h>

int date1[11],date2[11]; /* Setting up all the variables */
int limits[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; /* The number of days in each month */
int d1,d2,m1,m2,y1,y2,i,a,z,c,m,n,s,x,p,leap1,leap2,v;

int main(void)
 {  
 
  for (i = 0; i < 11; i++)     /* This will take the first date and insert it into the matrix date1 with each character split up  */
  {
    date1[i] = getchar();
    if (date1[i] == '\n')
      break;
  }
  
  for (i = 0; i < 11; i++)     /* Same as above but for the second date */
  {
    date2[i] = getchar();
    if (date2[i] == '\n')
      break;
  }

  for (i = 0; i < 11; i++)     /* Tests to see if the right characters are used */
  {
    m = date1[i];
    n = date2[i];
    s = 1;
    p = 1;
    for (x = 48; x <= 57; x++)
    {
     if (m == x || m == 47 || m == 45 || m == 10 || m == 0)  /* Checks the correct characters in ascii format */
      s = 0;
     if (n == x || n == 47 || n == 45 || n == 10 || n == 0)
      p = 0;
    }
    if (s == 1 || p == 1)
      fprintf(stderr, "Wrong character used\n");
    } 
  
  /* the next bunch of if test is just looking at the matrix and converting
     the answers into numbers they are testing to see if you put one or two
     digits in. It inserts the date, month and year into d1 m1 y1 respectivley.
     The minus 48 part is to get the numbers to work out right, I don't
     know why this is so but it works! */  
  
  if (date1[1] == '/' || date1[1] == '-')
  {
    d1 = date1[0] - 48;
    if (date1[3] == '/' || date1[3] == '-')
    {
      m1 = date1[2] - 48;
      y1 = ((date1[4] - 48) * 1000)+((date1[5] - 48) * 100)+((date1[6]  - 48) * 10) + (date1[7] - 48);
    }
    if (date1[4] == '/' || date1[4] == '-')
    {
      m1 = ((date1[2] - 48) * 10) + (date1[3] - 48);
      y1 = ((date1[5] - 48) * 1000)+((date1[6] - 48) * 100)+((date1[7] - 48) * 10) + (date1[8] - 48);
    }
   }
  if (date1[2] == '/' || date1[2] == '-')
  {
    d1 = ((date1[0] - 48) * 10) + (date1[1] - 48);
    if (date1[4] == '/' || date1[4] == '-')
    {
      m1 = date1[3] - 48;
      y1 = ((date1[5] - 48) * 1000)+((date1[6] - 48) * 100)+((date1[7] - 48) * 10) + (date1[8] - 48);
    }
    if (date1[5] == '/' || date1[5] == '-')
    {
      m1 = ((date1[3] - 48) * 10) + (date1[4] - 48);
      y1 = ((date1[6] - 48) * 1000)+((date1[7] - 48) * 100)+((date1[8] - 48) * 10) + (date1[9] - 48);
    }
   }
   
  /* The next set of if tests are the same as before but for the second date */  
  
  if (date2[1] == '/' || date2[1] == '-')
  {
    d2 = date2[0] - 48;
    if (date2[3] == '/' || date2[3] == '-')
    {
      m2 = date2[2] - 48;
      y2 = ((date2[4] - 48) * 1000)+((date2[5] - 48) * 100)+((date2[6]  - 48) * 10) + (date2[7] - 48);
    }
    if (date2[4] == '/' || date2[4] == '-')
    {
      m2 = ((date2[2] - 48) * 10) + (date2[3] - 48);
      y2 = ((date2[5] - 48) * 1000)+((date2[6] - 48) * 100)+((date2[7] - 48) * 10) + (date2[8] - 48);
    }
   }
  if (date2[2] == '/' || date2[2] == '-')
  {
    d2 = ((date2[0] - 48) * 10) + (date2[1] - 48);
    if (date2[4] == '/' || date2[4] == '-')
    {
      m2 = date2[3] - 48;
      y2 = ((date2[5] - 48) * 1000)+((date2[6] - 48) * 100)+((date2[7] - 48) * 10) + (date2[8] - 48);
    }
    if (date2[5] == '/' || date2[5] == '-')
    {
      m2 = ((date2[3] - 48) * 10) + (date2[4] - 48);
      y2 = ((date2[6] - 48) * 1000)+((date2[7] - 48) * 100)+((date2[8] - 48) * 10) + (date2[9] - 48);
    }
   }

  /* This next part checks to see if the inputed data is a valid date */
  if (y1 > 10000 || y2 > 10000)
    fprintf(stderr, "Year is too big\n");
  if (y1 <= 0 || y2 <= 0)
    fprintf(stderr, "Year is too small\n");
  if (m1 > 12 || m2 > 12)
    fprintf(stderr, "Month is too big\n");
  if (m1 <= 0 || m2 <= 0)
    fprintf(stderr, "Month is too small\n");
  v = 1;                                      /* This part is to make sure that on a leap year the 29th of feb isnt too many days */
  if (limits[m1] < d1 || limits[m2] < d2)
     v = 0;
  if ((y1%4) == 0 && m1 == 2 && d1 == 29)
     v = 1;
  if ((y2%4) == 0 && m2 == 2 && d2 == 29)
     v = 1;
  if (v == 0)
    fprintf(stderr, "There isnt that many days in that month\n");
  if (d1 <= 0 || d2 <= 0)
    fprintf(stderr, "The day is too small\n");


  /* The next part adds however many days are needed for different years */
  for (i = 0; i <= ((y2 - y1) - 1); i++)
  {
    if (((y1 + i)%4) != 0)
     c = c + 365;
    else
     c = c + 366;
  }
  
  /* This part looks to see if the months are the same and then just works out
  the differnce in days */
  if(m2 == m1)
  {
    c = c + (d2 - d1);
  }
  
  /* The next part looks to see which is the greater month then calculates
     the amount of days between them */
  else
  {
   if (m1 < m2)
    {
      if ((y1%4) == 0 && m1 == 2)
      c = c + limits[m1] + 1 - d1;
      else
      c = c + limits[m1] - d1;
      ++m1;
      do {
       if(m1 == m2)
         break;
       if ((y1%4) == 0 && m1 == 2)
       c = c + limits[m1] +1;
       else
       c = c + limits[m1];
       ++m1;
     } while(m1 == m2);
     c = c + d2;
    }
   if (m1 > m2)
    {
      if ((y2%4) == 0 && m2 == 2)
      c = c - limits[m2] + 1 + d2;
      else
      c = c - limits[m2] + d2;
      ++m2;
      do {
       if (m1 == m2)
         break;
       if ((y2%4) == 0 && m2 == 2)
       c = c - limits[m2] + 1;
       else
       c = c - limits[m2];
       ++m2;
     } while(m1 == m2);
     c = c - d1;
    }
   }
   
   /* Now this part just prints out the difference of days to the standard
      output */
   printf("%i\n",c);
  system("PAUSE");
  return 0;
  }
