-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem22.java
executable file
·67 lines (45 loc) · 1.28 KB
/
Problem22.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
64
65
66
67
import java.util.*;
import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
public class helloworld {
public static void main(String []args)
throws IOException {
//System.out.println("Hello World");
Scanner s = new Scanner(new File("names.txt"));
ReadValue(s);
System.out.println("Answer: ");
}
public static void ReadValue(Scanner s) {
s = s.useDelimiter(",");
StringBuffer newName;
List<String> names = new ArrayList<String>();
String[]finalNames;
while (s.hasNext()) {
String name = s.next();
newName = new StringBuffer(name);
newName.deleteCharAt(0);
newName.deleteCharAt(newName.length() - 1);
names.add(newName.toString());
}
Collections.sort(names);
/*for (String name : names) {
System.out.println(name);
}*/
CalcScore(names);
}
public static void CalcScore (List<String> names) {
int sum = 0;
long sumScore = 0l;
//System.out.println(names.get(0));
//System.out.println(names.get(0).charAt(0) + names.get(0).charAt(1));
for (int i = 1; i <= names.size(); i++) {
for (int j = 0; j < names.get(i-1).length(); j++) {
sum += (names.get(i-1).charAt(j) - 64);
}
sumScore += sum * (i);
sum = 0;
}
System.out.println(sumScore);
}
}