forked from ashishjohn1908/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextParseApp.java
More file actions
61 lines (47 loc) · 1.62 KB
/
Copy pathTextParseApp.java
File metadata and controls
61 lines (47 loc) · 1.62 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
58
59
60
/**
* Created by IntelliJ IDEA.
* User: plamen
* Date: 26-Jul-2010
* Time: 21:32:25
* To change this template use File | Settings | File Templates.
*/
import java.util.*;
import java.io.*;
class TextParseApp {
private static BufferedReader standard = null;
public static void readLine() {
try {
ArrayList<String> strings = new ArrayList<String>();
standard = new BufferedReader(new InputStreamReader(System.in));
String inline = standard.readLine();
StringTokenizer st = new StringTokenizer(inline.toLowerCase());
while (st.hasMoreTokens()) {
strings.add(st.nextToken());
}
HashMap<String, Integer> map = new HashMap<String, Integer>();
int count = 0;
for (int i = 0; i < strings.size(); i++) {
count = 0;
for (int j = 0; j < strings.size(); j++) {
if (strings.get(i).equals(strings.get(j)))
count++;
}
if (!map.containsKey(strings.get(i))) {
map.put(strings.get(i), count);
} else {
map.remove(strings.get(i));
map.put(strings.get(i), count);
}
}
System.out.println(map.toString());
for (String s : map.keySet()) {
System.out.println(s + " : " + map.get(s));
}
} catch (Exception e) {
System.out.println("");
}
}
public static void main(String args[]) throws IOException {
readLine();
}
}