-
Notifications
You must be signed in to change notification settings - Fork 0
/
P22.java
40 lines (36 loc) · 957 Bytes
/
P22.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
/**
* Project Euler #22 solution
*
* by Jayant Sinha
*
*/
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Scanner;
public class P22 {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(new File("names.txt")).useDelimiter("[\",]+");
ArrayList<String> text = new ArrayList<String>();
while (in.hasNext()) {
text.add(in.next());
}
Collections.sort(text);
Iterator itr = text.iterator();
String str = "";
long soln=0;
int sum =0;
int ind =1;
while (itr.hasNext()){
str = String.valueOf(itr.next());
sum=0;
for (int i = 0; i<=str.length()-1;i++){
sum += str.charAt(i)%65+1;
}
soln += sum*ind;
ind++;
}
System.out.println(soln);
}
}