Tweaked day 1 solutions
[ou-summer-of-code-2017.git] / anton / SummerOfCode / src / summerofcode / Day0.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 Day0
11 {
12 public static void main(String[] args) throws Exception
13 {
14 Scanner sc = new Scanner(new FileReader("00-prices.txt"));
15
16 String id, loc, bestId = "";
17 int nullarbor = 0;
18 int price, extras, nextCost;
19 int bestCost = Integer.MAX_VALUE;
20
21 while(sc.hasNext())
22 {
23 id = sc.next();
24 price = sc.nextInt();
25 loc = sc.next();
26 extras = sc.nextInt();
27
28 if(loc.contains("Nullarbor"))
29 nullarbor++;
30
31 nextCost = price + extras - Math.min(extras, 500);
32
33 if(nextCost < bestCost)
34 {
35 bestCost = nextCost;
36 bestId = id;
37 }
38 }
39
40 System.out.println("Nullarbor holidays " + nullarbor);
41 System.out.println("Best price holiday " + bestCost + " id " + bestId );
42 }
43
44 }