-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoomar.java
More file actions
59 lines (53 loc) · 2.02 KB
/
Copy pathoomar.java
File metadata and controls
59 lines (53 loc) · 2.02 KB
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
52
53
54
55
56
57
import java.io.*;
import java.util.*;
/**
* Created by SMudgal on 4/10/2016.
*/
public class oomar {
public static void main (String args[])
{
int[] alp = null;
HashMap<Character,Integer> alpha = new HashMap<Character,Integer>();
String word;
try {
BufferedReader bufferedReader = new BufferedReader(new FileReader("input.txt"));
int test_cases = Integer.parseInt(bufferedReader.readLine());
while (test_cases > 0)
{
alp = new int[26];
word = bufferedReader.readLine();
for (int i=0;i<word.length();i++)
{
alp[(word.charAt(i)-97)]++;
alpha.put(word.charAt(i),alp[word.charAt(i)-97]);
}
Set<Map.Entry<Character, Integer>> al_set = alpha.entrySet();
List<Map.Entry<Character, Integer>> list = new ArrayList<Map.Entry<Character, Integer>>(al_set);
Collections.sort( list, new Comparator<Map.Entry<Character, Integer>>()
{
public int compare( Map.Entry<Character, Integer> o1, Map.Entry<Character, Integer> o2 )
{
if (o1.getValue().equals(o2.getValue()))
return (o2.getKey().compareTo(o1.getKey()));
return (o1.getValue()).compareTo( o2.getValue() );
}
} );
for (char i='z';i>='a';i--)
{
if (!alpha.containsKey(i))
{
System.out.print(i+" ");
}
}
for(Map.Entry<Character, Integer> entry:list)
System.out.print(entry.getKey()+" ");
test_cases--;
System.out.println();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}