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 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 = []
with open('p022_names.txt') as f:
for line in f:
for i in line.split(','):
names.append(i[1:-1])
names.sort()
alphabet = [chr(i) for i in range(65, 65+26)]
total = 0
for name in names:
count = 0
for char in name:
count += alphabet.index(char) + 1
index = names.index(name) + 1
total += (count * index)
print(total)
Problem 22的更多相关文章
- (Problem 22)Names scores
Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-tho ...
- qsc oj 22 哗啦啦村的刁难(3)(随机数,神题)
哗啦啦村的刁难(3) 发布时间: 2017年2月28日 20:00 最后更新: 2017年2月28日 20:01 时间限制: 1000ms 内存限制: 128M 描述 哗啦啦村作为喵哈哈村 ...
- Common Bugs in C Programming
There are some Common Bugs in C Programming. Most of the contents are directly from or modified from ...
- electrica writeup
关于 caesum.com 网上上的题目,分类有Sokoban,Ciphers,Maths,Executables,Programming,Steganography,Misc.题目有点难度,在努力奋 ...
- LeetCode题目按公司分类
LinkedIn(39) 1 Two Sum 23.0% Easy 21 Merge Two Sorted Lists 35.4% Easy 23 Merge k Sorted Lists 23.3% ...
- Codeforces 22B Bargaining Table
http://www.codeforces.com/problemset/problem/22/B 题意:求出n*m的方格图中全是0的矩阵的最大周长 思路:枚举 #include<cstdio& ...
- 【codeforces 22C】 System Administrator
[题目链接]:http://codeforces.com/problemset/problem/22/C [题意] 给你n个点; 要求你构造一个含m条边的无向图; 使得任意两点之间都联通; 同时,要求 ...
- Python练习题 049:Project Euler 022:姓名分值
本题来自 Project Euler 第22题:https://projecteuler.net/problem=22 ''' Project Euler: Problem 22: Names sco ...
- 《DSP using MATLAB》Problem 6.22
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
随机推荐
- 《Effective C++ 》学习笔记——条款12
***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...
- ios添加麦克风访问权限
不然程序崩溃: This app has crashed because it attempted to access privacy-sensitive data without a usage d ...
- luogu1312 Mayan游戏 剪枝
题目大意 Mayan puzzle是最近流行起来的一个游戏.游戏界面是一个77 行\times 5×5列的棋盘,上面堆放着一些方块,方块不能悬空堆放,即方块必须放在最下面一行,或者放在其他方块之上.游 ...
- Google android source code build 问题总结【转】
本文转载自:http://light3moon.com/2015/01/31/Google%20android%20source%20code%20build%20%E9%97%AE%E9%A2%98 ...
- SQL 优化记录
1. 对Where 语句的法则 1.1 避免在WHERE子句中使用in,not in,or 或者having. 可以使用 exist 和not exist代替 in和not in. 可以使用表链接代 ...
- C# winform 组件---- folderBrowserDialog与openFileDialog(转)
C# winform 组件---- folderBrowserDialog与openFileDialog 2009-06-27 13:36 2153人阅读 评论(1) 收藏 举报 winformc#b ...
- B1202 [HNOI2005]狡猾的商人 并查集
其实就是并查集的题.维护一个前缀和,然后用并查集维护前缀和,每次判断是否合理就行了. 题干: Description 刁姹接到一个任务,为税务部门调查一位商人的账本,看看账本是不是伪造的.账本上记录了 ...
- XML案例(使用JAXP进行SAX解析)
1.Book.java package cn.itcast.sax; public class Book { private String name; private String author; p ...
- php的self和this
<?phpclass ss{ public static $code; public function __construct( $code ) { self::$code=$code; //这 ...
- Python 35 线程(2)线程特性、守护线程、线程互斥锁
一:线程特性介绍 from threading import Thread import time n=100 def task(): global n n=0 if __name__ == '__m ...