HACKER RANK Project Euler 22 - Names Scores - Solution.'Py'

Project Euler Challenges-22 - Names Scores Solution
Problem Statement
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 16+1+13+5+12+1=48, is the 5th name in the list. So, PAMELA would obtain a score of 5×48=240.
You are given Q queries, each query is a name, you have to print the score.
Input Format 
The first line contains an integer N , i.e., number of names. 
Next N lines will contain a Name. 
Followed by integer Q followed by Q lines each having a word.
Output Format 
Print the values corresponding to each test case.
Constraints 
1N5200 
length of each word will be less than 12 
1Q100
Sample Input
5
ALEX
LUIS
JAMES
BRIAN
PAMELA
1
PAMELA
Sample Output
240

Solution:

# Enter your code here. Read input from STDIN. Print output to STDOUT
t = input()
list = []
while (t>0):
    t-=1
    list.append(raw_input())
    list = sorted(list)
    
n = input()
while (n>0):
    n-=1
    k = raw_input()
    for i in list:
        if k == i:
            sum1 = int(0)
            check = len(k)
            while (check):
                sum1 += (ord(k[check-1])-64)
                check -= 1
    print sum1 * (list.index(k)+1)

                

Thanks for Visiting, Hope this helps you....

Comments

Popular Posts