-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStandAlone.java
150 lines (74 loc) · 2.92 KB
/
StandAlone.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import java.io.*;
import java.util.*;
public class StandAlone {
public static void main (String[] args) {
File file = new File(args[0]); // Reading content dIDs
InputStream input = null;
FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;
try {
fis = new FileInputStream(file);
// Here BufferedInputStream is added for fast reading.
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
// HashMap<String, String> mapper = new HashMap<String, String>();
TreeMap<String, String> mapper = new TreeMap<String, String>();
int i=1;
while (dis.available() != 0) {
// System.out.println(dis.readLine());
try {
String [] tokens = dis.readLine().split("\\,+");
String year = tokens[1];
String player = tokens[0];
String runs = tokens[8];
String value = player+","+runs;
if (mapper.containsKey(year))
{
String newvalue = mapper.get(year);
newvalue = newvalue+"~"+value;
mapper.put(year,newvalue);
}
else
mapper.put(year,value);
// System.out.println ( i++ + " " + year + " " + player + " " + runs);
}catch (ArrayIndexOutOfBoundsException e) {
// e.printStackTrace();
}
// reduce (year,player,runs);
}
File Outputfile = new File("output.txt");
FileWriter fw = new FileWriter(Outputfile.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
for ( String key : mapper.keySet())
{
// System.out.println(key + " - " + mapper.get(key));
//System.out.println("In the year " + key);
String token1[] = mapper.get(key).split("\\~+");
int maxTemp = Integer.MIN_VALUE;
String toPrint="";
for ( String we : token1 )
{
// System.out.println (we);
String token2[] = we.split("\\,+");
// System.out.print(" player " + token2[0]+ " Scored " + token2[1] + "\n");
int run = Integer.parseInt(token2[1]);
maxTemp = Math.max(maxTemp, run);
if ( maxTemp == run)
// System.out.println("In the year " + key + " player " + token2[0] + "Scored max runs " + token2[1] );
toPrint=" " + key + " " + token2[0] + " " + token2[1];
}
//System.out.println(toPrint);
bw.write(toPrint+"\n");
}
fis.close();
bis.close();
dis.close();
bw.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
} // end of main
}