/home/toolbox/public_html/solutions/4/482/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
10 #define TRUE (1 == 1)
11 #define FALSE (1 != 1)
12
13 #define DEBUG if (FALSE)
14
15
16 /*
17 * Author: Isaac Traxler
18 * Date: 2015-03-25
19 * Purpose:
20 * Problem: 482
21 */
22
23 /*
24 * This template reads lines of data at a time until end of file.
25 */
26
27 #define MAX_LINE 50
28 #define MAX_NUMBERS 1000000
29
30
31 int numCases;
32 char line[MAX_NUMBERS];
33 int numbers[MAX_NUMBERS];
34 char values[MAX_NUMBERS][MAX_LINE];
35 int numCnt;
36
37
38 void init()
39 {
40 /* FUNCTION init */
41 scanf(" %d ", &numCases);
42 DEBUG printf("numCases = %d\n", numCases);
43 } /* FUNCTION init */
44
45 void dump()
46 {
47 /* FUNCTION dump */
48 } /* FUNCTION dump */
49
50 void getInput()
51 {
52 /* FUNCTION getInput */
53 char *tmp;
54 char *token;
55 int cnt;
56 int i;
57
58 /* get first line of input */
59 fgets(line, sizeof(line), stdin);
60 line[strlen(line) - 1] = 0;
61 /* extract the numbers */
62 tmp = line;
63 numCnt = 1;
64 token = strtok(tmp, " ");
65 while (NULL != token)
66 {
67 /* while something left in string */
68 sscanf(token, " %d ", &numbers[numCnt]);
69 DEBUG printf("[%s] %d: %d\n", token, numCnt, numbers[numCnt]);
70 numCnt++;
71 token = strtok(NULL, " ");
72 } /* while something left in string */
73 /* load values */
74 fgets(line, sizeof(line), stdin);
75 line[strlen(line) - 1] = 0;
76 tmp = line;
77 DEBUG printf("line[%s]\n", tmp);
78 token = strtok(tmp, " ");
79 DEBUG printf("token [%s]\n", token);
80 for (i=1; i<numCnt; i++)
81 {
82 /* for */
83 sscanf(token, "%s", values[numbers[i]]);
84 DEBUG printf("%d -- %d: token [%s]\n", i, numbers[i], values[numbers[i]]);
85 token = strtok(NULL, " ");
86 } /* for */
87 fgets(line, sizeof(line), stdin);
88 line[strlen(line) - 1] = 0;
89 DEBUG printf("skip line[%s]\n", line);
90 } /* FUNCTION getInput */
91
92 void process()
93 {
94 /* FUNCTION process */
95 int i;
96
97 for (i=1; i<numCnt; i++)
98 {
99 /* for */
100 printf("%s\n", values[i]);
101 } /* for */
102 } /* FUNCTION process */
103
104 int main()
105 {
106 /* main */
107 int i;
108
109 init();
110 for (i=1; i<=numCases; i++)
111 {
112 /* for */
113 getInput();
114 process();
115 if (i < numCases)
116 {
117 printf("\n");
118 }
119 } /* for */
120
121 return EXIT_SUCCESS;
122 } /* main */
123