/home/toolbox/public_html/solutions/102/10252/c.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 #define DEBUG1 if (TRUE)
15
16 /*
17 * Author:
18 * Date:
19 * Purpose:
20 * Problem:
21 */
22
23 /*
24 * This template reads data until a terminating value is reached.
25 */
26 #define MAX_LINE 1002
27 char line1[MAX_LINE];
28 char line2[MAX_LINE];
29
30 int letterCount1[27];
31 int letterCount2[27];
32
33 void init()
34 {
35 /* FUNCTION init */
36 int i;
37 for (i = 0; i < 26; i++)
38 {
39 letterCount1[i] = 0;
40 letterCount2[i] = 0;
41 }
42 } /* FUNCTION init */
43
44 void dump()
45 {
46 /* FUNCTION dump */
47 } /* FUNCTION dump */
48
49 int getInput()
50 {
51 /* FUNCTION getInput */
52 int dataReadFlag;
53 int temp;
54 dataReadFlag = 0 < scanf("%s ", line1);
55 DEBUG printf("%d\n",temp);
56 DEBUG dataReadFlag = (0 < temp);
57 if (dataReadFlag)
58 {
59 scanf("%s ", line2);
60 }
61 return (dataReadFlag);
62 } /* FUNCTION getInput */
63
64 void process()
65 {
66 /* FUNCTION process */
67 int j;
68 int c;
69 int min;
70 DEBUG printf("line1 = %s \nline2 = %s\n",line1,line2);
71 for (j = 0; j < strlen(line1); j++)
72 {
73 letterCount1[line1[j]-'a']++;
74 }
75
76 DEBUG for (j = 0; j < 26; j++)
77 {
78 printf("%c = %d\n",j+'a',letterCount1[j]);
79 }
80
81 for (j = 0; j < strlen(line2); j++)
82 {
83 letterCount2[line2[j]-'a']++;
84 }
85
86 DEBUG for (j = 0; j < 26; j++)
87 {
88 printf("%c = %d\n",j+'a',letterCount2[j]);
89 }
90
91 for (j = 0; j < 26; j++)
92 {
93 if (letterCount1[j] > letterCount2[j])
94 {
95 /*letterCount1 always holds minimum
96 letterCount1[j] = letterCount2[j];*/
97 min = letterCount2[j];
98 }
99 else
100 {
101 min = letterCount1[j];
102 }
103
104 DEBUG printf("min=%d\n",min);
105
106 for (c = 0; c < min ; c++)
107 {
108 printf("%c",j+'a');
109 }
110 }
111 printf("\n");
112
113 } /* FUNCTION process */
114
115 int main ()
116 {
117 /* main */
118 int moreToDo;
119
120 moreToDo = getInput();
121 while (moreToDo)
122 {
123 /* while */
124 init();
125 process();
126 moreToDo = getInput();
127 } /* while */
128
129 return EXIT_SUCCESS;
130 } /* main */
131
132