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的更多相关文章

  1. (Problem 22)Names scores

    Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-tho ...

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

    哗啦啦村的刁难(3) 发布时间: 2017年2月28日 20:00   最后更新: 2017年2月28日 20:01   时间限制: 1000ms   内存限制: 128M 描述 哗啦啦村作为喵哈哈村 ...

  3. Common Bugs in C Programming

    There are some Common Bugs in C Programming. Most of the contents are directly from or modified from ...

  4. electrica writeup

    关于 caesum.com 网上上的题目,分类有Sokoban,Ciphers,Maths,Executables,Programming,Steganography,Misc.题目有点难度,在努力奋 ...

  5. LeetCode题目按公司分类

    LinkedIn(39) 1 Two Sum 23.0% Easy 21 Merge Two Sorted Lists 35.4% Easy 23 Merge k Sorted Lists 23.3% ...

  6. Codeforces 22B Bargaining Table

    http://www.codeforces.com/problemset/problem/22/B 题意:求出n*m的方格图中全是0的矩阵的最大周长 思路:枚举 #include<cstdio& ...

  7. 【codeforces 22C】 System Administrator

    [题目链接]:http://codeforces.com/problemset/problem/22/C [题意] 给你n个点; 要求你构造一个含m条边的无向图; 使得任意两点之间都联通; 同时,要求 ...

  8. Python练习题 049:Project Euler 022:姓名分值

    本题来自 Project Euler 第22题:https://projecteuler.net/problem=22 ''' Project Euler: Problem 22: Names sco ...

  9. 《DSP using MATLAB》Problem 6.22

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

随机推荐

  1. HDU 4405 Aeroplane chess (概率DP求期望)

    题意:有一个n个点的飞行棋,问从0点掷骰子(1~6)走到n点须要步数的期望 当中有m个跳跃a,b表示走到a点能够直接跳到b点. dp[ i ]表示从i点走到n点的期望,在正常情况下i点能够到走到i+1 ...

  2. 自定cell(XIB)团购思路

    自定cell(XIB)团购思路 步骤一.先解析plist文件,创建model层数据. - (instancetype)initWithDict:(NSDictionary *)dict {     s ...

  3. thymeleaf+springboot找不到html,只返回了字符串

    在浏览器用链接http://localhost:8080/city/page/list 访问时页面上只出现了cityList字样,预期是返回cityList.html 解决:在controller中使 ...

  4. web 前端学习笔记

    <!DOCTYPE HTML> <head> <style type="text/css"> body {  background: #ff00 ...

  5. 动手分析安卓仿QQ联系人列表TreeView控件

    因项目需要需要用到仿QQ联系人列表的控件样式,于是网上找到一个轮子(https://github.com/TealerProg/TreeView),工作完成现在简单分析一下这个源码.   一. 需要用 ...

  6. Winform设计-小百货 涵盖基础插件学习(适合新手)

    Winform设计-小百货 涵盖基础插件学习(适合新手)   第一次写winform,主要是为了加快对  事件的 理解. 代码如下: private void Form1_Load(object se ...

  7. kafka的topic和分区策略——log entry和消息id索引文件

    Topic在逻辑上可以被认为是一个在的queue,每条消费都必须指定它的topic,可以简单理解为必须指明把这条消息放进哪个queue里. 为了使得Kafka的吞吐率可以水平扩展,物理上把topic分 ...

  8. C# Event.ClickCount 解决垃圾鼠标带来的烦恼

    今天调试遇到个Bug,百思不得其解的是在自己的设备上重来不重现,在测试机上百分百重现,如下: 问题:点击一次Button执行两次Click操作 分析:看Log的确是执行了两次,就像真的点击了两次But ...

  9. 自己对javascript闭包的了解

    目录 闭包的概念 谈谈函数执行环境,作用域链以及变量对象 闭包和函数柯里化 闭包造成的额外的内存占用  (注意我说的不是“内存泄漏”!) 闭包只能取得包含函数的最后一个值 正文 前言: 在这篇文章里, ...

  10. BZOJ 1914 计算几何

    思路: 我们可以算不合法的 如果三个点都在同一侧 就不合法.. 用总方案数减掉就可以了 (有神奇的实现方法...) //By SiriusRen #include <cmath> #inc ...