/home/toolbox/public_html/solutions/12/1203/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 <stdint.h>
7 #include <math.h>
8 #include <stdlib.h>
9 #include <ctype.h>
10
11 #define TRUE (1 == 1)
12 #define FALSE (1 != 1)
13
14 #define DEBUG if (FALSE)
15
16
17 /*
18 * Author: Isaac Traxler
19 * Date: 2023-11-07
20 * Purpose: fun
21 * Problem: 1203
22 */
23
24 /*
25 * This template reads lines of data at a time until end of file.
26 */
27
28 #define MAX_LINE 257
29 #define MAX_QUERIES 3002
30
31 char line[MAX_LINE];
32 int query[MAX_QUERIES];
33 int k;
34
35 void init()
36 {
37 /* FUNCTION init */
38 int i;
39
40 for (i=0; MAX_QUERIES>i; i++)
41 {
42 query[i] = 0;
43 };
44 } /* FUNCTION init */
45
46 void dump()
47 {
48 /* FUNCTION dump */
49 } /* FUNCTION dump */
50
51 void getInput()
52 {
53 /* FUNCTION getInput */
54 int x;
55 int y;
56 char tmp[50];
57
58 fgets(line, MAX_LINE, stdin);
59 while ('R' == line[0])
60 {
61 /* get query */
62 sscanf(line, "%s %d %d", tmp, &x, &y);
63 DEBUG printf("(x %d) (y %d) (tmp:%s)\n", x, y, tmp);
64 query[x] = y;
65 fgets(line, MAX_LINE, stdin);
66 } /* get query */
67 scanf(" %d ", &k);
68 } /* FUNCTION getInput */
69
70 void process()
71 {
72 /* FUNCTION process */
73 int i;
74 int j;
75 int cnt = 0;
76
77 for (i=1; cnt < k; i++)
78 {
79 /* for each p[ossible time */
80 for (j=0; j<MAX_QUERIES; j++)
81 {
82 /* for each possible query */
83 if (0 < query[j])
84 {
85 /* valid query */
86 if (0 == (i % query[j]))
87 {
88 /* print the query */
89 if (cnt < k)
90 {
91 /* still printing */
92 printf("%d\n", j);
93 } /* still printing */
94 cnt++;
95 } /* print the query */
96 } /* valid query */
97 } /* for each possible query */
98 } /* for each p[ossible time */
99 } /* FUNCTION process */
100
101 int main()
102 {
103 /* main */
104 init();
105 getInput();
106 process();
107 return EXIT_SUCCESS;
108 } /* main */
109