/home/toolbox/public_html/solutions/104/10474/b.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
10 #define TRUE (1 == 1)
11 #define FALSE (1 != 1)
12
13 #define DEBUG if (FALSE)
14
15 /*
16 * Author: Isaac Traxler
17 * Date: 2016-03-29
18 * Purpose: fun
19 * Problem: 10474 - Where is the marble?
20 */
21
22 /*
23 * This template reads data until a terminating value is reached.
24 */
25
26 #define MAXX 10004
27
28 int cnt;
29 int marbles[MAXX];
30 int query;
31
32 void init()
33 {
34 /* FUNCTION init */
35 } /* FUNCTION init */
36
37 void dump()
38 {
39 /* FUNCTION dump */
40 } /* FUNCTION dump */
41
42 int getInput()
43 {
44 /* FUNCTION getInput */
45 int dataReadFlag = FALSE;
46 int i;
47 int tmp;
48
49 scanf(" %d %d ", &cnt, &query);
50 if ((0 != cnt) || (0 != query))
51 {
52 /* something to do */
53 dataReadFlag = TRUE;
54 for (i=0; MAXX>i; i++)
55 {
56 marbles[i] = 0;
57 }
58 for (i=0; i<cnt; i++)
59 {
60 /* for */
61 scanf(" %d ", &tmp);
62 if (0 == marbles[tmp])
63 {
64 /* first occurrence -- save it */
65 marbles[tmp] = i+2; /* it seems indexing starts at 2 for some reason */
66 } /* first occurrence -- save it */
67 } /* for */
68 } /* something to do */
69
70 return (dataReadFlag);
71 } /* FUNCTION getInput */
72
73 void process()
74 {
75 /* FUNCTION process */
76 int i;
77 int num;
78
79 for (i=0; i<query; i++)
80 {
81 /* for each query */
82 scanf(" %d ", &num);
83 if (0 == marbles[num])
84 {
85 /* not found */
86 printf("%d not found\n", num);
87 } /* not found */
88 else
89 {
90 /* found */
91 printf("%d found at %d\n", num, marbles[num]);
92 } /* found */
93 } /* for each query */
94 } /* FUNCTION process */
95
96 int main()
97 {
98 /* main */
99 int moreToDo;
100 int cse = 1;
101
102 init();
103 moreToDo = getInput();
104 while (moreToDo)
105 {
106 /* while */
107 printf("CASE# %d:\n", cse);
108 cse++;
109 process();
110 moreToDo = getInput();
111 } /* while */
112
113 return EXIT_SUCCESS;
114 } /* main */
115