-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuyOneGetOne.java
42 lines (40 loc) · 1.22 KB
/
BuyOneGetOne.java
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
package problems.codechef;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
/**
* Created by Arpit on 04-Jan-16.
*/
public class BuyOneGetOne {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t,ans;
char ch[];
HashMap<Character,Integer>map;
ArrayList<Integer>temp;
t=Integer.parseInt(br.readLine());
while (t-->0){
ch=br.readLine().toCharArray();
map=new HashMap<>();
int a=0;
ans=0;
for (int i = 0; i < ch.length; i++) {
if (map.containsKey(ch[i])){
a=map.get(ch[i]);
a++;
map.put(ch[i],a);
}
else map.put(ch[i],1);
}
temp=new ArrayList<>(map.values());
int size=temp.size();
for (int i = 0; i < size; i++) {
if (temp.get(i)%2==0)ans+=temp.get(i)/2;
else ans+=temp.get(i)/2+1;
}
System.out.println(ans);
}
}
}