Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
Many people quite often want to know how much older (or younger) they are than their friends.
You will be given pairs of birthdates and you are to determine how many days older the oldest is than the youngest. All dates will be between January 1, 1910 and December 31, 1999. The format of the date will be month, followed by day, followed by year for the first date and then the same information for the second date. Each input item will be on a separate line. Terminate the program when the month of the first date is a -1.
Example Input:
8
4
58
5
21
57
1
15
85
6
25
96
12
27
78
7
11
75
-1
In the first example above, the first date is 8/4/58 (August 4, 1958) and the second date is 5/21/57 (May 21, 1957).
Sample Output:
8/4/58 is 440 days after 5/21/57
1/15/85 is 4179 days before 6/25/96
12/27/78 is 1265 days after 7/11/75
NOTE: The exact spacing above is not critical. Having date is # days before or after date is. Specifying date as day/month/year is imporant, but spacing is not critical.
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
Source Code for a Solution to this Problem
// preprocessor directives #include <stdio.h> #define QUIT -1 // typedefs typedef struct node { int month,day,year; }DATE; // prototypes int convert(DATE first, DATE second,int month[]); int main(void) { int i,days; int month[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; DATE first,second; char string[7]; scanf("%d",&first.month); while( first.month != QUIT) { scanf("%d %d %d %d %d",&first.day,&first.year, &second.month,&second.day,&second.year); if(second.year > first.year) { strcpy(string,"before"); days = convert(second,first,month); } //if else { strcpy(string,"after"); days = convert(first,second,month); } //else printf("%d/%d/%d is %d days %s %d/%d/%d.\n",first.month,first.day, first.year,days,string,second.month,second.day,second.year); scanf("%d",&first.month); } // while return 0; } /* convert: accepts copies of the date structures returns the integer number of days between two dates */ int convert(DATE first, DATE second, int month[]) { int i,j,days = 0; days += ( (first.year - second.year) - 1) * 365; for(i=1; i < first.month; i++) days += month[i]; for(i = second.month + 1; i <= 12; i++) days += month[i]; days += month[second.month] - second.day; days += first.day; for(i = second.year + 1; i < first.year; i++) if( i % 4 == 0 ) days++; if( first.year % 4 == 0 && first.month >= 2) days++; if( (second.year % 4) == 0 && second.month < 3) days++; return days; } // convert
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
8 4 58 5 21 57 1 15 85 6 25 96 12 27 78 7 11 75 0
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
8/4/58 is 440 days after 5/21/57. 1/15/85 is 4179 days before 6/25/96. 12/27/78 is 1265 days after 7/11/75.
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
8 4 58 5 21 57 1 15 85 6 25 96 12 27 78 7 11 75 11 09 90 04 10 99 04 15 99 04 15 89 04 02 99 04 02 28 05 21 91 05 21 75 -1
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
8/4/58 is 440 days after 5/21/57. 1/15/85 is 4179 days before 6/25/96. 12/27/78 is 1265 days after 7/11/75. 11/9/90 is 3074 days before 4/10/99. 4/15/99 is 3652 days after 4/15/89. 4/2/99 is 25932 days after 4/2/28. 5/21/91 is 5844 days after 5/21/75.
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
4 8 99 12 5 91 01 01 10 04 10 99 12 31 99 01 01 10 10 08 57 08 04 58 01 01 20 12 19 33 10 19 28 10 11 11 -1
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
4/8/99 is 2681 days after 12/5/91. 1/1/10 is 32606 days before 4/10/99. 12/31/99 is 32871 days after 1/1/10. 10/8/57 is 300 days before 8/4/58. 1/1/20 is 5101 days before 12/19/33. 10/19/28 is 6218 days after 10/11/11.
Return to the Top of Page, First Page, Novice Problem Set, or Veteran Problem Set.
Return to the LSU High School Programming Contest Homepage