-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday2.java
92 lines (82 loc) · 2.87 KB
/
day2.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
import java.io.File;
import java.io.IOException;
// import java.util.Arrays;
import java.util.Scanner;
class Main {
public static void main(String[] args) throws IOException {
File f = new File("./day2input.txt");
try (Scanner in = new Scanner(f)) {
char[][] rounds = new char[2500][2];
int i = 0;
char[] temp;
int total = 0;
while (in.hasNextLine()) {
temp = in.next().toCharArray();
rounds[i][0] = temp[0];
temp = in.next().toCharArray();
rounds[i][1] = temp[0];
in.nextLine();
i++;
}
for (i = 0; i < rounds.length; i++) {
int roundvalue = 0;
int oppvalue = 0;
switch (rounds[i][0]) {
case 'A': // rock
oppvalue = 1;
break;
case 'B': // paper
oppvalue = 2;
break;
case 'C': // scissors
oppvalue = 3;
break;
}
switch (rounds[i][1]) {
case 'X': // lose
switch (oppvalue) {
case 1:
roundvalue = 3 + 0;
break;
case 2:
roundvalue = 1 + 0;
break;
case 3:
roundvalue = 2 + 0;
break;
}
break;
case 'Y': // draw
switch (oppvalue) {
case 1:
roundvalue = 1 + 3;
break;
case 2:
roundvalue = 2 + 3;
break;
case 3:
roundvalue = 3 + 3;
break;
}
break;
case 'Z': // win
switch (oppvalue) {
case 1:
roundvalue = 2 + 6;
break;
case 2:
roundvalue = 3 + 6;
break;
case 3:
roundvalue = 1 + 6;
break;
}
break;
}
total += roundvalue;
}
System.out.println(total);
in.close();
}
}
}