-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHolidayCode2.java
More file actions
61 lines (46 loc) · 1.39 KB
/
HolidayCode2.java
File metadata and controls
61 lines (46 loc) · 1.39 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
import java.util.*;
public class HolidayCode2 {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int lastOutput = 5;
for(int i = 0; i < 5; i++){
String rawIn = input.nextLine();
String[] orders = rawIn.split("");
int output = lastOutput;
for(int j = 0; j < orders.length; j++){
String letter = orders[j];
if(letter.equals("U")){
if(output > 2 && (output != 4 && (output != 5 && output != 9))){
//Subtract what is needed
if(output == 3 || output == 13){
output -= 2;
} else {
output -= 4;
}
}
} else if (letter.equals("D")){
if(output < 12 && (output != 10 && (output != 5 && output != 9))){
//Add what is needed
if(output == 1 || output == 11){
output += 2;
} else {
output += 4;
}
}
} else if (letter.equals("L")){
if(output > 2 && (output != 5 && (output != 10 && output != 13))){
//Subtract what is needed
output -= 1;
}
} else {
if(output < 12 && (output != 9 && (output != 4 && output != 1))){
//Subtract what is needed
output += 1;
}
}
}
System.out.println(output);
lastOutput = output;
}
}
}