-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem22.cs
More file actions
28 lines (22 loc) · 721 Bytes
/
Problem22.cs
File metadata and controls
28 lines (22 loc) · 721 Bytes
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
using System;
class Problem22
{
static void Main(string[] args)
{
string fileText = System.IO.File.ReadAllText("problem22_data.txt");
string[] names = fileText.Split(new char[] { '"', ',' },
StringSplitOptions.RemoveEmptyEntries);
Array.Sort(names);
int totalScore = 0;
for (int i = 0; i < names.Length; i++)
{
int nameValue = 0;
char[] nameArray = names[i].ToCharArray();
for (int j = 0; j < nameArray.Length; j++)
nameValue += (int)nameArray[j] - 64;
nameValue *= (i + 1);
totalScore += nameValue;
}
Console.WriteLine(totalScore);
}
}