FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ProjectEuler-Java/Sol22.java at master · JoshP/ProjectEuler-Java · GitHub
JoshP
ProjectEuler-Java
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
ProjectEuler-Java
/
Sol22.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
41 lines (34 loc) · 1.08 KB
Breadcrumbs
ProjectEuler-Java
/
Sol22.java
Copy path
File metadata and controls
41 lines (34 loc) · 1.08 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
java
.
util
.*;
import
java
.
io
.*;
import
java
.
math
.*;
public
class
Sol22
extends
BaseSolution
{
public
void
runSolution
() {
try
{
Scanner
scanner
=
new
Scanner
(
new
FileInputStream
(
"Sol22.txt"
),
"UTF-8"
);
List
<
String
>
nameList
=
new
ArrayList
<
String
>(
6000
);
int
sum
=
0
;
while
(
scanner
.
hasNextLine
()) {
String
names
[] =
scanner
.
nextLine
().
split
(
","
);
for
(
String
name
:
names
) {
nameList
.
add
(
name
.
substring
(
1
,
name
.
length
() -
1
));
}
Collections
.
sort
(
nameList
);
int
i
=
1
;
for
(
String
name
:
nameList
) {
sum
+=
i
*
getNameScore
(
name
);
i
++;
}
}
System
.
out
.
println
(
sum
);
}
catch
(
Exception
ex
) {
System
.
err
.
println
(
ex
);
}
}
private
int
getNameScore
(
String
name
) {
int
score
=
0
;
for
(
char
c
:
name
.
toCharArray
()) {
score
+= (
int
)
c
-
64
;
}
return
score
;
}
}
Back
|
FazBrowse Home
|
New Git URL