/home/toolbox/public_html/solutions/115/11588/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: 2017-03-20
20 * Purpose: fun
21 * Problem: 11588 - Image Coding
22 */
23
24 /*
25 * This template reads data a specified number of times.
26 */
27
28 #define MAX_LENGTH 32
29 #define LETTERS 26
30
31 int numberOfTimes;
32 int r; /* rows */
33 int c; /* columns */
34 int m; /* important byte count */
35 int n; /* non-important byte cont */
36 char buf[MAX_LENGTH]; /* hold each line of the image */
37 int a[LETTERS]; /* count of occurrence of each letter */
38
39 void init()
40 {
41 /* FUNCTION init */
42 scanf("%d ", &numberOfTimes);
43 } /* FUNCTION init */
44
45 void dump()
46 {
47 /* FUNCTION dump */
48 } /* FUNCTION dump */
49
50 void getInput()
51 {
52 /* FUNCTION getInput */
53 scanf(" %d %d %d %d ", &r, &c, &m, &n);
54 } /* FUNCTION getInput */
55
56 void process()
57 {
58 /* FUNCTION process */
59 int i;
60 int j;
61 int mx;
62 int cnt;
63 int other;
64
65 /* 1 - clear count array */
66 for (i=0; i<LETTERS; i++)
67 {
68 a[i] = 0;
69 }
70
71 /* 2 - process each line incrementing letter occurrence */
72 for (j=0; j<r; j++)
73 {
74 /* each line */
75 scanf(" %s ", buf);
76 for (i=0; i<c; i++)
77 {
78 /* each char on a line */
79 a[buf[i] - 'A']++;
80 } /* each char on a line */
81 } /* each line */
82
83 /* 3 - find max occurrences */
84 mx = 0;
85 cnt = 0;
86 for (i=0; i<LETTERS; i++)
87 {
88 /* for each possibel letter */
89 if (mx < a[i])
90 {
91 /* found new max */
92 mx = a[i];
93 cnt = 1;
94 } /* found new max */
95 else
96 {
97 /* no new max */
98 if (mx == a[i])
99 {
100 /* another letter with current max */
101 cnt++;
102 } /* another letter with current max */
103 } /* no new max */
104 } /* for each possibel letter */
105
106 /* 4 - now deal with all non-max (sum up all non-max) */
107 other = 0;
108 for (i=0; i<LETTERS; i++)
109 {
110 /* for each possibel letter */
111 if (mx > a[i])
112 {
113 other = other + a[i];
114 }
115 } /* for each possibel letter */
116
117 /* 5 - output result */
118 printf("%d\n", (mx * m * cnt) + (other * n));
119
120 } /* FUNCTION process */
121
122 int main()
123 {
124 /* main */
125 int i;
126
127 init();
128 for (i=0; i<numberOfTimes; i++)
129 {
130 /* while */
131 getInput();
132 printf("Case %d: ", i+1);
133 process();
134 } /* while */
135
136 return EXIT_SUCCESS;
137 } /* main */
138
139