forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10252.cpp
48 lines (45 loc) · 776 Bytes
/
10252.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <bits/stdc++.h>
using namespace std;
char line1[1010], line2[1010];
int main()
{
while (cin.getline(line1, 1010))
{
cin.getline(line2, 1010);
int i;
int cnt1[26], cnt2[26];
memset(cnt1, 0, sizeof(cnt1));
memset(cnt2, 0, sizeof(cnt2));
for (i = 0; line1[i]; i++)
{
line1[i] = tolower(line1[i]);
if (isalpha(line1[i]))
{
cnt1[line1[i] - 'a']++;
}
}
for (i = 0; line2[i]; i++)
{
line2[i] = tolower(line2[i]);
if (isalpha(line2[i]))
{
cnt2[line2[i] - 'a']++;
}
}
for (i = 0; i < 26; i++)
{
if (cnt1[i] && cnt2[i])
{
int j;
int min;
min = cnt1[i] < cnt2[i] ? cnt1[i] : cnt2[i];
for (j = 0; j < min; j++)
{
cout << (char)(i + 'a');
}
}
}
cout << endl;
}
return 0;
}