-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintCost.java
More file actions
55 lines (43 loc) · 2.32 KB
/
PrintCost.java
File metadata and controls
55 lines (43 loc) · 2.32 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
import java.util.Arrays;
import java.util.Scanner;
public class PrintCost {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int values [] = new int [130];
String key = "! 9 \" 6 # 24 $ 29 % 22 " +
"& 24 ' 3 ( 12 ) 12 * 17 + 13 " +
", 7 - 7 . 4 / 10 0 22 1 19 " +
"2 22 3 23 4 21 5 27 6 26 7 16 " +
"8 23 9 26 : 8 ; 11 < 10 = 14 " +
"> 10 ? 15 @ 32 A 24 B 29 C 20 " +
"D 26 E 26 F 20 G 25 H 25 I 18 " +
"J 18 K 21 L 16 M 28 N 25 O 26 " +
"P 23 Q 31 R 28 S 25 T 16 U 23 " +
"V 19 W 26 X 18 Y 14 Z 22 [ 18 "+
"\\ 10 ] 18 ^ 7 _ 8 ` 3 a 23 "+
"b 25 c 17 d 25 e 23 f 18 g 30 "+
"h 21 i 15 j 20 k 21 l 16 m 22 "+
"n 18 o 20 p 25 q 25 r 13 s 21 "+
"t 17 u 17 v 13 w 19 x 13 y 24 "+
"z 19 { 18 | 12 } 18 ~ 9";
Scanner keySc = new Scanner(key);
while(keySc.hasNext())
{
char symbol = keySc.next().charAt(0);
int value = keySc.nextInt();
values [(int)symbol] = value;
}
//System.out.println(Arrays.toString(values));
String line = "";
while(sc.hasNextLine())
{
int cost = 0;
line = sc.nextLine();
for(int i = 0; i < line.length(); i++)
{
cost += values[(int)(line.charAt(i))];
}
System.out.println(cost);
}
}
}