/home/toolbox/public_html/solutions/125/12541/a.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdlib.h>
7 #include <math.h>
8 #include <stdint.h>
9 #include <ctype.h>
10
11 #define TRUE (1 == 1)
12 #define FALSE (1 != 1)
13
14 #define DEBUG if (FALSE)
15
16 /* fprintf(stderr, "functionName: message", varslist); */
17
18 /*
19 * Author: Isaac Traxler
20 * Date: 2021-11-05
21 * Purpose: fun
22 * Problem: 12541 - Birthdates
23 */
24
25 /*
26 * This template reads data a specified number of times.
27 */
28
29 #define YOUNGEST_NAME_LENGTH 20
30 #define YOUNGEST 0
31 #define OLDEST 1
32
33 int numberOfTimes;
34 char names[2][YOUNGEST_NAME_LENGTH];
35 char person[YOUNGEST_NAME_LENGTH];
36 int dates[2]; /* date becomes yyyymmdd */
37 int year;
38 int month;
39 int day;
40 int tmp;
41
42 /* same min in location 0 and max in location 1 */
43
44 void init()
45 {
46 /* FUNCTION init */
47 scanf("%d ", &numberOfTimes);
48 /* always promised at least one person
49 * Load them into min and max
50 */
51 scanf(" %s %d %d %d ", person, &day, &month, &year);
52 strcpy(names[OLDEST], person);
53 strcpy(names[YOUNGEST], person);
54 dates[OLDEST] = (year*10000) + (month * 100) + day;
55 dates[YOUNGEST] = dates[OLDEST];
56 /* decrement count since first one processed */
57 numberOfTimes--;
58 } /* FUNCTION init */
59
60 void dump()
61 {
62 /* FUNCTION dump */
63 } /* FUNCTION dump */
64
65 void getInput()
66 {
67 /* FUNCTION getInput */
68 scanf(" %s %d %d %d ", person, &day, &month, &year);
69 } /* FUNCTION getInput */
70
71 void process()
72 {
73 /* FUNCTION process */
74 tmp = (year*10000) + (month * 100) + day;
75 if (tmp < dates[OLDEST])
76 {
77 /* new min found */
78 dates[OLDEST] = tmp;
79 strcpy(names[OLDEST], person);
80 } /* new min found */
81 if (tmp > dates[YOUNGEST])
82 {
83 /* new min found */
84 dates[YOUNGEST] = tmp;
85 strcpy(names[YOUNGEST], person);
86 } /* new min found */
87 } /* FUNCTION process */
88
89 int main()
90 {
91 /* main */
92 int i;
93
94 init();
95 for (i=0; i<numberOfTimes; i++)
96 {
97 /* while */
98 getInput();
99 process();
100 } /* while */
101 printf("%s\n", names[YOUNGEST]);
102 printf("%s\n", names[OLDEST]);
103
104 return EXIT_SUCCESS;
105 } /* main */
106
107