/home/toolbox/public_html/solutions/113/11340/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
10 #define TRUE (1 == 1)
11 #define FALSE (1 != 1)
12
13 #define DEBUG if (FALSE)
14
15 /* fprintf(stderr, "functionName: message", varslist); */
16
17 /*
18 * Author: Isaac Traxler
19 * Date: 2015-03-22
20 * Purpose:
21 * Problem: 11340
22 */
23
24 /*
25 * This template reads data a specified number of times.
26 */
27
28 #define MAX_LETTERS 256
29 #define MAX_LINE 10009
30
31 int numberOfTimes;
32 int letCnt;
33 int pay[MAX_LETTERS];
34 int lineCnt;
35 unsigned char line[MAX_LINE];
36 unsigned long total;
37
38 void init()
39 {
40 /* FUNCTION init */
41 scanf("%d ", &numberOfTimes);
42 } /* FUNCTION init */
43
44 void dump()
45 {
46 /* FUNCTION dump */
47 } /* FUNCTION dump */
48
49 void caseReset()
50 {
51 /* FUNCTION caseReset */
52 int i;
53
54 total = 0;
55 for (i=0; MAX_LETTERS>i; i++)
56 {
57 /* for */
58 pay[i] = 0;
59 } /* for */
60
61 } /* FUNCTION caseReset */
62
63 void getInput()
64 {
65 /* FUNCTION getInput */
66 int i;
67 unsigned char c;
68 unsigned long amount;
69
70 caseReset();
71 scanf(" %d ", &letCnt);
72 for (i=0; i<letCnt; i++)
73 {
74 /* for */
75 scanf("%c %d ", &c, &amount);
76 pay[c] = amount;
77 } /* for */
78 } /* FUNCTION getInput */
79
80 unsigned long processLine()
81 {
82 /* FUNCTION processLine */
83 int i;
84 unsigned long tot = 0;
85 unsigned char c;
86
87 for (i=0; strlen(line)>i; i++)
88 {
89 /* for */
90 c = line[i];
91 tot = tot + pay[c];
92 } /* for */
93 DEBUG printf("%d [%s]\n", tot, line);
94 return tot;
95 } /* FUNCTION processLine */
96
97 void process()
98 {
99 /* FUNCTION process */
100 int i;
101 int cents;
102 unsigned long dollars;
103
104 scanf(" %d ", &lineCnt);
105 for (i=0; i<lineCnt; i++)
106 {
107 /* for */
108 /*
109 scanf(" %[^\n]", line);
110 */
111 fgets(line, MAX_LINE, stdin);
112 line[strlen(line) - 1] = 0;
113 total = total + processLine();
114 DEBUG printf("%d: [%s]\n", strlen(line), line);
115 } /* for */
116 cents = total % 100;
117 dollars = total / 100;
118 printf("%lu.%02d$\n", dollars, cents);
119 } /* FUNCTION process */
120
121 int main()
122 {
123 /* main */
124 int i;
125
126 init();
127 for (i=0; i<numberOfTimes; i++)
128 {
129 /* while */
130 getInput();
131 process();
132 } /* while */
133
134 return EXIT_SUCCESS;
135 } /* main */
136
137