-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListingNames.java
41 lines (39 loc) · 1.16 KB
/
ListingNames.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
package problems.codechef;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
/**
* Created by Arpit on 10-Dec-15.
*/
public class ListingNames {
public static void main(String[] args) {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try {
int t=Integer.parseInt(br.readLine());
SortedMap<String,Integer> map=new TreeMap<String,Integer>();
for (int i=0;i<t;i++){
String s=br.readLine();
if(!map.containsKey(s)){
map.put(s,1);
}
else {
Integer a=map.get(s);
a++;
map.put(s,a);
}
}
Set s=map.keySet();
Iterator itr=s.iterator();
while (itr.hasNext()){
String p= (String) itr.next();
System.out.println(p+" "+map.get(p));
}
} catch (IOException e) {
e.printStackTrace();
}
}
}