问题描述:
Usingnames.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 93853
= 49714.
What is the total of all the name scores in the file?
由于题目的names.txt文件比较大,这里只列举几个数据作为测试:
1. 快排
2.计算姓名的分数
(function(){
//*********************data*************************
var data = new Array("MARY","PATRICIA","LINDA","BARBARA","ELIZABETH","JENNIFER","MARIA","SUSAN","MARGARET","DOROTHY","LISA","NANCY","KAREN","BETTY","HELEN","SANDRA");
//***************************************************
var nameScore = function score(name,multiply){
var s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var sc = 0;
for(var i = 0; i < name.length;i++)
{
var c = name[i].toUpperCase();
var idx = name.indexOf(c);
if(idx < 0) {console.log("invalid name format !!!");return ;}
sc += idx + 1;
}
return sc * multiply;
}
var sort = function quick(left,right,depth){
if (left>= right) return;
var refNum= data[left];
var low =left;
var high =right;
while (low< high)
{
while(low < high && data[high] >= refNum)
high--;
if(low < high)
data[low++] = data[high];
while(low < high && data[low] < refNum)
low++;
if(low < high)
data[high--] = data[low];
}
data[low] =refNum;
quick(left,right - 1);
quick(left + 1,right);
}
sort(0,data.length-1,1);
for(var i = 0 ;i < data.length;i++)
console.log("name : " + data[i] + ", score : " + nameScore(data[i],i+1));
})();
分享到:
相关推荐
减少CurseForge和WowInterface的插件下载计数,类似于wow-scrape-addon-download-count,但具有更多选项。 它是什么? 这是带有CLI的Node.JS脚本,可让您从一个或多个魔兽世界插件中快速获取当前下载计数,这些插件...
Count Docula添加了三个指令,这些指令采用空的内联链接的形式,如下所示: [](!import "./path/doc.md" as filename) [](!anchor my-anchor-name) [](!export my-anchor-name) 伪指令用于声明对其他文档的依赖...
这是一个基于的倒计时网页,用于南非covid-19相关的锁定。 通过更改index.js中的这些变量来自定义链接和名称 let name = 'Your Name' let instagramURL = '...运行开发服务器: npm run dev# oryarn dev 使用浏览
if (document.form.count.value > 100 || document.form.count.value ) { alert("输入数值不能小于零大于100!"); document.form.count.focus(); return false; } if (document.form.MESSAGE.value.length) ...
// QRCode for JavaScript // // Copyright (c) 2009 Kazuhiko Arase // // URL: http://www.d-project.com/ // // Licensed under the MIT license: // http://www.opensource.org/licenses/mit-license.php // // ...
<xsl:output name="xhtml" method="xhtml" indent="yes" omit-xml-declaration="yes"/> name="testNgXslt.outputDir"/> <xsl:param name="testNgXslt.cssFile"/> <xsl:param name="testNgXslt....
if (document.form.count.value > 100 || document.form.count.value ) { alert("输入数值不能小于零大于100!"); document.form.count.focus(); return false; } if (document.form.MESSAGE.value.length) { alert...
data="dataList"> <el-table-column label="id" prop="id"></el-table-column> <el-table-column label="name" prop="name"> <template v-slot="props"> <el-input-number :min="0" v-model="props.row.count...
name: "counter", initialState: { count: 0, }, reducers: { increment: (state, action) => { state.count += action.payload.change; }, decrement: (state, action) => { state.count -= action.payl
JavaScript的RegExp对象和String对象定义了使用正则表达式来执行强大的模式匹配和文本检索与替换函数的方法. 在JavaScript中,正则表达式是由一个RegExp对象表示的.当然,可以使用一个RegExp()构造函数来创建RegExp...
计数器API Javascript库 在查看我们的文档。 如何使用 按名称增加 import { CounterAPI } from "counterapi" ; const counter = new CounterAPI ( ) ; counter . up ( "test" ) . then ( ( res ) => { console . ...
圆环面 通过CLI操作CircleCI REST API 这是实验模块。 安装 npm install -g torus 用法 设置API令牌 首先,您应该获取。 然后通过以下方式设置此令牌... Build count, default is 30, max is 100 --offset, -o Def
"name" : "MongoDB", "type" : "database", "count" : 1, "info" : { x : 203, y : 102 } } coll.insert(doc) myDoc = coll.findOne(); print(myDoc); // Now, lets add lots of little documents to the ...
if (this.pageCount >= startPage + 10) strHtml += '<span title="Next 10 Pages"><a href="javascript:' + this.name + '.toPage(' + (startPage + 10) + ');">...</a></span>'; if (nextPage > this....
npm run profile:node -- --testName=$name --type=$type --count=$iterationCount 在当前节点环境中分析给定的测试。 类型可能是以下之一: 巴别塔 babel运行时 巴别岛 打字稿 es5 es6 npm run build 将测试...
<tr><td align=right>类型:</td><td><input type="radio" name="ntype" checked value="0">文件夹 <input type="radio" name="ntype" value="1">文件 <tr><td align=right>名称: <input type="text" size="40" ...
Lolcat CSS属性 整体CSS属性翻译为Lolcat ... 'animation-iteration-count': 'animashun-iterashun-count' 'animation-name': 'animashun-naym' 'animation-play-state': 'animashun-pulay-state' 'animation-timing
js代码: 代码如下:[removed] //全局变量,代表文件域的个数,并用该变量区分文件域的name属性 var file_count = 0; //增加文件 域 function additem(id) { if (file_count > 9) { alert(“最u22810 10个u25991 ...
可以通过--log-dir命令行参数提供另一个文件夹,例如: node count-traffic.js --log-dir=/some/other/path 该脚本将不处理*.gz文件,以避免过多的内存消耗。 如果找到文件夹,它将扫描其中的所有文件。 它将计算...