-
Notifications
You must be signed in to change notification settings - Fork 0
/
one.java
65 lines (56 loc) · 1.6 KB
/
one.java
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
62
63
import java.io.*;
import java.util.*;
/**
* Word Game (scrabblesque) points calculator
*
* @author Michael Vartan
* @author Ian Goegebuer
*/
class one {
public static void main(String[] args) throws Exception {
String line;
ArrayList<Integer> values = new ArrayList<>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
while((line=reader.readLine())!=null) {
if(values.size()<27) {
// first 27 digits transmitted are scores for A-Z, wildcard
String[] tokens = line.split(" ");
for(String numStr:tokens)
values.add(Integer.parseInt(numStr));
}
else {
// after that, lines should be sent in pairs
String line2 = reader.readLine(); // get second half of pair
int wordMultiplier=1, wordValue=0;
//line 1 is the multipliers. "...3.." would have a 3x char multiplier
char[] multipliers = line.toCharArray();
//line 2 is the actual letters of the word
char[] letters = line2.toCharArray();
int lineValue = 0;
for(int i=0; i<multipliers.length;i++) {
int letterValue =0;
if((letters[i]>='A' && letters[i] <= 'Z'))
letterValue = values.get(letters[i]-'A');
else
letterValue = values.get(26); // wildcard
switch(multipliers[i]) {
case '2':
letterValue*=2;
break;
case '3':
letterValue*=3;
break;
case 'd':
wordMultiplier*=2;
break;
case 't':
wordMultiplier*=3;
break;
}
wordValue+=letterValue;
}
System.out.println(lineValue+wordValue*wordMultiplier);
}
}
}
}