-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday1-2.java
35 lines (31 loc) · 984 Bytes
/
day1-2.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
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
class day1_2 {
public static void main(String[] aaa) throws Exception {
BufferedReader in = new BufferedReader(new FileReader(new File("inputs/day1")));
int[] left = new int[1000];
List<Integer> right = new ArrayList<>();
String line;
int i = 0;
while ((line = in.readLine()) != null) {
String[] split = line.split(" ");
left[i] = Integer.parseInt(split[0]);
right.add(i, Integer.parseInt(split[1]));
i++;
}
int sum = 0;
for (i = 0; i < 1000; i++) {
int count = 0;
for (int j = 0; j < right.size(); j++) {
if (left[i] == right.get(j)) {
count++;
}
}
sum += left[i] * count;
}
System.out.println(sum);
}
}