Added Java solutions from Anton
[ou-summer-of-code-2017.git] / anton / SummerOfCode / src / summerofcode / Day2.java
1 package summerofcode;
2
3 import java.io.FileReader;
4 import java.util.Scanner;
5
6 /**
7 *
8 * @author Anton Dil
9 */
10 public class Day2
11 {
12 public static void main(String[] args) throws Exception
13 {
14 Scanner sc = new Scanner(new FileReader("02-lifts.txt"));
15 int exit = Integer.MIN_VALUE; //replaceable floor value
16 String input = "";
17 int floor = 0;
18
19 while (sc.hasNext())
20 {
21 input = sc.next(); //just one line of input in fact
22 }
23
24 System.out.println("Input was " + input);
25
26 for (char ch : input.toCharArray())
27 {
28 switch (ch)
29 {
30 case 'v':
31 floor--;
32 break;
33 case '^':
34 floor++;
35 break;
36 case '=':
37 if (floor > exit)
38 {
39 exit = floor;
40 }
41 }
42 }
43
44 System.out.printf("final floor %d, highest exit %d%n", floor, exit);
45 }
46 }