-
Notifications
You must be signed in to change notification settings - Fork 0
/
AoC2_part1.java
70 lines (66 loc) · 1.87 KB
/
AoC2_part1.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
import java.io.*;
public class AoC2_part1 {
public void solve() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
/*
* A, X: ROCK (1)
* B, Y: PAPER (2)
* C, Z: SCISSORS (3)
* score 6 if win
* score 3 if draw
* 0 if lose
*/
String line;
long totalScore = 0;
while((line = br.readLine()).compareTo("*") != 0) {
String[] inputs = line.split(" ");
totalScore += getShpaeScore(inputs[1]);
totalScore += getRoundResult(inputs);
}
br.close();
bw.write(String.valueOf(totalScore));
bw.newLine();
bw.flush();
bw.close();
}
private long getShpaeScore(String shape) {
return switch (shape) {
case "X" -> 1;
case "Y" -> 2;
case "Z" -> 3;
default -> 0;
};
}
private long getRoundResult(String[] inputs) {
// oppenent : ROCK
if (inputs[0].compareTo("A") == 0) {
if (inputs[1].compareTo("X") == 0) {
return 3;
}
if (inputs[1].compareTo("Y") == 0) {
return 6;
}
return 0;
}
if (inputs[0].compareTo("B") == 0) {
if (inputs[1].compareTo("X") == 0) {
return 0;
}
if (inputs[1].compareTo("Y") == 0) {
return 3;
}
return 6;
}
if (inputs[0].compareTo("C") == 0) {
if (inputs[1].compareTo("X") == 0) {
return 6;
}
if (inputs[1].compareTo("Y") == 0) {
return 0;
}
return 3;
}
return 0;
}
}