projecteuler---->problem=22----Names scores

sing names.txt (right click and ‘Save Link/Target As...‘), a 46K text file containing over 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 is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a score of 938
53 = 49714.

What is the total of all the name scores in the file?

翻译:

下载这个文档names.txt,这个46KB的文本文档包含超过五千个姓氏,你要先把它们按字母表顺序排列好,然后把姓氏中每个字母在字母表中的索引加总,最后将所有索引的和乘以该姓氏在列表中的索引,就得到该姓氏的分值了。

例如,假定你已经把姓氏列表排好了,找到一个姓氏叫Colin,它的字母索引总和为3 + 15 + 12 + 9 + 14 = 53,已经它是第938个姓氏,于是它的分值就是938 × 53 = 49714。

你知道所有名字的总分值是多少吗?

import fileinput,string
f=open("22.txt","r")
s=f.readline()
info=s.split(',')
info.sort()
resu=0
for i in range(0,len(info)):
    addsum=0
    for j in range(0,len(info[i])):
        if info[i][j]>='A' and info[i][j] <= 'Z':
            addsum+=ord(info[i][j])-ord('A')+1
    addsum*=(i+1)
    resu+=addsum
print resu

projecteuler---->problem=22----Names scores,布布扣,bubuko.com

时间: 2024-11-01 09:11:46

projecteuler---->problem=22----Names scores的相关文章

Project Euler:Problem 22 Names scores

Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over 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 alph

Project-Euler problem 1-50

最近闲的做了下Project Euler 上的题目,前面50题都比较简单,简单总结下.代码一般是Python和C/C++的 用Python 做这些题目简直是酸爽啊 一下代码可能不一定是我的,因为不知道论坛里面的回复不是永久的,所以我的代码有的丢了,可能找个和我的意思相近的代码.题目翻译是从 欧拉计划 | Project Euler 中文翻译站上面Copy 的表告我. Problem 1  Multiples of 3 and 5 10以下的自然数中,属于3和5的倍数的有3,5,6和9,它们之和是

Problem 22

Problem 22 Using names.txt (https://projecteuler.net/problem=22)(right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical valu

欧拉计划(python) problem 22

Names scores Problem 22 Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multipl

SPOJ Problem 22:Triangle From Centroid

已知三角形重心到三边的距离和其中一边,求面积和重心到垂心的距离. 计算几何..纯数学题 #include<cstdio> #include<cmath> int t; double x,y,z,a,s,d,r1,r2; int main(){ scanf("%d",&t); while(t--){ scanf("%lf%lf%lf%lf",&a,&x,&y,&z); s=3*a*x/2; r1=pow(

Project Eluer - 22

题目: Names scores Problem 22 Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, mul

qsc oj 22 哗啦啦村的刁难(3)(随机数,神题)

哗啦啦村的刁难(3) 发布时间: 2017年2月28日 20:00   最后更新: 2017年2月28日 20:01   时间限制: 1000ms   内存限制: 128M 描述 哗啦啦村作为喵哈哈村的对头,于是他们准备给喵哈哈村一个好看. 哗啦啦村的三号长老——大先生,就提出了以下问题: 现在这道题有两组数据,每组输入数据都是1,. 但是,第一组测试数据你需要输出1,第二组你需要输出2. 你怎么输出呢? 输入 1 输出 这道题只包含两组测试数据,第一组测试数据应该输出1,第二组你应该输出2.

欧拉计划21-23题

21.Amicable numbers Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). If d(a) = b and d(b) = a, where a  b, then a and b are an amicable pair and each of a and b are called amicable numbers. For

Google C++ 代码规范

Google C++ Style Guide Table of Contents Header Files Self-contained Headers The #define Guard Forward Declarations Inline Functions Names and Order of Includes Scoping Namespaces Unnamed Namespaces and Static Variables Nonmember, Static Member, and

Google C++ Style Guide----英文版

转载请注明出处<http://blog.csdn.net/qianqin_2014/article/details/51354326> Background C++ is the main development language used by many of Google's open-source projects. As every C++ programmer knows, the language has many powerful features, but this power