Skip to content

Commit 059b4b2

Browse files
committed
solution of problem B, codeforces round 734, Div 3
1 parent 2fbdffa commit 059b4b2

File tree

1 file changed

+103
-0
lines changed
  • Codeforces/livecontest/Round734Div3

1 file changed

+103
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package livecontest.Round734Div3;
2+
3+
import java.io.PrintWriter;
4+
import java.io.BufferedReader;
5+
import java.io.InputStreamReader;
6+
import java.io.IOException;
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
import java.util.StringTokenizer;
10+
11+
public class B {
12+
13+
public static void main(String[] args) {
14+
FastReader sc = new FastReader();
15+
PrintWriter out = new PrintWriter(System.out);
16+
17+
int t = sc.nextInt();
18+
for (int tt = 0; tt < t; tt++) {
19+
String s = sc.next();
20+
solveTask(s, out);
21+
}
22+
out.close();
23+
}
24+
25+
private static void solveTask(String s, PrintWriter out) {
26+
int colors = 0;
27+
HashMap<Character, Integer> map = new HashMap<>();
28+
29+
for (char ch : s.toCharArray()) {
30+
if (!map.containsKey(ch))
31+
map.put(ch, 1);
32+
else {
33+
map.put(ch, map.get(ch) + 1);
34+
}
35+
}
36+
37+
int count1s = 0;
38+
39+
for (Map.Entry<Character, Integer> entries : map.entrySet()) {
40+
int value = entries.getValue();
41+
42+
if (value == 1) {
43+
count1s++;
44+
} else if (value >= 2) {
45+
colors++;
46+
}
47+
}
48+
49+
colors = colors + (count1s / 2);
50+
51+
out.println(colors);
52+
}
53+
54+
static class FastReader {
55+
BufferedReader br;
56+
StringTokenizer st;
57+
58+
FastReader() {
59+
br = new BufferedReader(new InputStreamReader(System.in));
60+
}
61+
62+
String next() {
63+
while (st == null || !st.hasMoreElements()) {
64+
try {
65+
st = new StringTokenizer(br.readLine());
66+
} catch (IOException e) {
67+
e.printStackTrace();
68+
}
69+
}
70+
return st.nextToken();
71+
}
72+
73+
int nextInt() {
74+
return Integer.parseInt(next());
75+
}
76+
77+
long nextLong() {
78+
return Long.parseLong(next());
79+
}
80+
81+
double nextDouble() {
82+
return Double.parseDouble(next());
83+
}
84+
85+
String nextLine() {
86+
String str = "";
87+
try {
88+
str = br.readLine();
89+
} catch (IOException e) {
90+
e.printStackTrace();
91+
}
92+
return str;
93+
}
94+
95+
int[] readArray(int n) {
96+
int[] temparr = new int[n];
97+
for (int i = 0; i < n; i++) {
98+
temparr[i] = nextInt();
99+
}
100+
return temparr;
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)