We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
//C#
using System;
using System.Collections.Generic;
class Solution {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string[] str = new string[n];
SortedDictionary<string, int> sorted = new SortedDictionary<string, int>();
for (int i = 0; i < n; i++)
{
int sum = 0;
str[i] = Console.ReadLine();
char[] characters = str[i].ToCharArray();
foreach (char ch in characters)
{
sum += (int)ch - 64;
}
sorted[str[i].ToUpper()] = sum;
}
var entryArray = new KeyValuePair<string, int>[sorted.Count];
sorted.CopyTo(entryArray, 0);
for (int i = 0; i < sorted.Count; i++)
{
int newNumber = entryArray[i].Value * (i + 1);
sorted[entryArray[i].Key] = newNumber;
}
int q = int.Parse(Console.ReadLine());
for (int i = 0; i < q; i++)
{
string name = Console.ReadLine();
if (sorted.ContainsKey(name.ToUpper()))
{
Console.WriteLine(sorted[name.ToUpper()]);
}
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Project Euler #22: Names scores
You are viewing a single comment's thread. Return to all comments →
//C# using System; using System.Collections.Generic;
class Solution { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] str = new string[n];
} }