forked from allicen/Java-1000
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarousel.java
More file actions
45 lines (39 loc) · 1.28 KB
/
Copy pathCarousel.java
File metadata and controls
45 lines (39 loc) · 1.28 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
package carousel;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Carousel {
private static ArrayList<Integer> answers = new ArrayList<>();
private static long pointTotal(){
int startScore = 3;
int mistakePenalty = 3;
long total = 0;
for(int i : answers){
if (i == 1){
total += startScore;
startScore++;
}else {
startScore = (startScore - mistakePenalty < mistakePenalty) ? mistakePenalty : startScore - mistakePenalty;
}
}
return total;
}
public static void main(String[] args) throws IOException {
FileReader file = new FileReader("input.txt");
Scanner sc = new Scanner(file);
while (sc.hasNextLine()){
StringTokenizer st = new StringTokenizer(sc.nextLine(), " ");
while (st.hasMoreTokens()){
answers.add(Integer.valueOf(st.nextToken()));
}
}
answers.remove(0);
long result = pointTotal();
FileWriter out = new FileWriter("output.txt");
out.write(String.valueOf(result));
out.close();
}
}