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.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. All Contests
  2. ProjectEuler+
  3. Project Euler #22: Names scores

Project Euler #22: Names scores

Problem
Submissions
Leaderboard
Discussions

This problem is a programming version of Problem 22 from projecteuler.net

You are given around five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score.

For example, when the list in sample is sorted into alphabetical order, PAMELA, which is worth , is the name in the list. So, PAMELA would obtain a score of .

You are given queries, each query is a name, you have to print the score.

Input Format

The first line contains an integer , i.e., number of names.
Next lines will contain a Name.
Followed by integer followed by lines each having a word.

Constraints

  • length of each word will be less than

Output Format

Print the values corresponding to each test case.

Sample Input

5
ALEX
LUIS
JAMES
BRIAN
PAMELA
1
PAMELA

Sample Output

240

Explanation

Explained in statement.

Author

shashank21j

Difficulty

Easy

Max Score

100

Submitted By

7815

Need Help?


View discussions
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits

Choose a translation


  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature