-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathProgramTemplate.java
More file actions
59 lines (49 loc) · 1.82 KB
/
Copy pathProgramTemplate.java
File metadata and controls
59 lines (49 loc) · 1.82 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
package program_template;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class ProgramTemplate {
private static int wordEnergy(int position) {
if (position < 10) {
return position;
}
return position/10 + position%10;
}
public static void main(String[] args) throws IOException {
int energy = 0;
String words = "abcdefghijklmnopqrstuvwxyz";
Scanner sc = new Scanner(new FileReader("input.txt"));
while (sc.hasNextLine()) {
char[] symbols = sc.nextLine().toCharArray();
for (char character : symbols) {
String symbol = String.valueOf(character);
if (words.contains(symbol.toLowerCase())) {
energy += wordEnergy(words.indexOf(symbol.toLowerCase())+1);
if (!symbol.toLowerCase().equals(symbol)) {
energy += 10;
}
} else if (symbol.equals(" ")) {
energy += 4;
} else if (symbol.equals(".")) {
energy += 5;
} else if (symbol.equals(";")) {
energy += 7;
} else if (symbol.equals(",")) {
energy += 2;
} else if ("=+-'\"".contains(symbol)) {
energy += 3;
} else if ("()".contains(symbol)) {
energy += 1;
} else if ("{}[]<>".contains(symbol)) {
energy += 8;
} else if (symbol.matches("\\d")) {
energy += 13 - Integer.parseInt(symbol);
}
}
}
PrintWriter out = new PrintWriter(System.out);
out.println(energy);
out.flush();
}
}