Repository navigation
Expand file tree
/
Copy pathday11.java
More file actions
99 lines (86 loc) · 3.08 KB
/
Copy pathday11.java
File metadata and controls
99 lines (86 loc) · 3.08 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
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
import java.io.FileNotFoundException;
import java.util.*;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
Scanner sc = new Scanner(new java.io.File("in.txt"));
List<Monkey> monkeys = new ArrayList<>();
Monkey basic = new Monkey();
for (int i = 0; i < 3; i++) {
monkeys.add(basic);
}
while (sc.hasNextLine()) {
String string = sc.nextLine();
Scanner helper = new Scanner(string);
helper.next();
String ind = helper.next().split(":")[0];
int monkeyIndex = Integer.parseInt(ind);
string = sc.nextLine();
helper = new Scanner(string);
helper.next();
helper.next();
while (helper.hasNext()) {
String another = helper.next().split(",")[0];
monkeys.get(monkeyIndex).items.add(Integer.parseInt(another));
}
string = sc.nextLine();
helper = new Scanner(string);
if (string.contains("+")) {
monkeys.get(monkeyIndex).isAddition = true;
} else {
monkeys.get(monkeyIndex).isAddition = false;
}
helper.next();
helper.next();
helper.next();
helper.next();
helper.next();
monkeys.get(monkeyIndex).amount = Integer.parseInt(helper.next());
string = sc.nextLine();
helper = new Scanner(string);
helper.next();
helper.next();
helper.next();
monkeys.get(monkeyIndex).divBy = Integer.parseInt(helper.next());
string = sc.nextLine();
helper = new Scanner(string);
helper.next();
helper.next();
helper.next();
helper.next();
helper.next();
monkeys.get(monkeyIndex).ifTrue = Integer.parseInt(helper.next());
string = sc.nextLine();
helper = new Scanner(string);
helper.next();
helper.next();
helper.next();
helper.next();
helper.next();
monkeys.get(monkeyIndex).ifFalse = Integer.parseInt(helper.next());
if (sc.hasNextLine()) {
sc.nextLine();
}
}
}
static class Monkey {
List<Integer> items;
int divBy;
int ifTrue;
int ifFalse;
boolean isAddition;
int amount;
public Monkey() {
this.items = new ArrayList<>();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Monkey monkey)) return false;
return divBy == monkey.divBy && ifTrue == monkey.ifTrue && ifFalse == monkey.ifFalse && isAddition == monkey.isAddition && amount == monkey.amount && Objects.equals(items, monkey.items);
}
@Override
public int hashCode() {
return Objects.hash(items, divBy, ifTrue, ifFalse, isAddition, amount);
}
}
}