-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB2_Wonderful_Coloring_2.cpp
51 lines (46 loc) · 1013 Bytes
/
B2_Wonderful_Coloring_2.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
49
50
51
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define ll long long
int main()
{
int t;
cin >> t;
while (t--)
{
string s;
map<char, int> m;
map<char, int>::iterator itr;
cin >> s;
if (s.length() == 1)
{
cout << 0 << endl;
}
else
{
for (long i = 0; i < s.length(); i++)
{
m[s[i]]++;
}
int same = 0, diff = 0;
for (itr = m.begin(); itr != m.end(); itr++)
{
if (itr->second >= 2)
{
same++;
}
if (itr->second == 1)
{
diff++;
}
}
if (diff == 1)
{
diff = 0;
}
//cout << samefreq << " " << difffreq << endl;
int ans = same + (diff / 2);
cout << ans << endl;
}
}
}