欧拉工程-问题22
原题链接 http://projecteuler.net/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 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 (右击然后’链接另存为…‘),一个大小为46K的文本文件,包含有查过5000个姓名,以字典顺序排列。然后计算给每个姓计算字母的值,乘以它在姓名列表的位置,得到一个姓名得分。
例如,当姓名表以字典顺序排列时,COLIN, 字母值为3 + 15 + 12 + 9 + 14 = 53,在姓名表中为第938个,最终,
COLIN的得分为938 * 53 = 49714。
求文件中所有姓名的得分总和。
解答:
这题没什么好说的,将名字排序,默认就是字典序了,然后按照说明算就行了。