Javascript(49 + 5635)* 10/2174 = 26.14
在线演示:
“真实词典”选项在投递箱上不起作用,但如果在真实Web服务器上运行,它将起作用。在Visual Studio开发服务器和Google Chrome中进行了测试。
https://dl.dropboxusercontent.com/u/141246873/leettranslator/index.html
得分:
49个leet项目= 49
资本化奖金= 5 * 49 = 245
字典查询奖励= 20 * 49 = 980
感叹号奖励* 3 = 90 * 49 = 4410
(项目+奖金)* 10 /(代码长度)
(49 + 5635)* 10/2174 = 26.14
码:
function IsInDict(e) { return W[e] } function translate(e) { words = e.split(" "); res = ""; for (var t in words) { ex = ""; function n(e, r, i) { var s = false; for (var o = 1; o <= e.length; o++) { var u = e.substring(0, o) === "!" || i; var a = et[e.substring(0, o)]; var f = e.substring(o); if (a) { s = true; if (f.length === 0) { if (u) { ex = r + a; words[t] = "" } } else n(f, r + a, u) } } if (i && !s && r) { ex = r; words[t] = e.split("").reverse().join("") } } n(words[t].split("").reverse().join(""), "", false); mes = []; function r(e, t) { for (var n = 1; n <= e.length; n++) { var i = tokens[e.substring(0, n)]; var s = e.substring(n); if (i) { mFound = true; if (s.length === 0) for (var o in i) { mes.push(t + i[o]) } else for (var o in i) r(s, t + i[o]) } } if (e.length > 1) r(e.substring(1), t + e.substring(0, 1)); else { mes.push(t + e) } } m = ""; if (words[t] !== "") { r(words[t].toLowerCase(), ""); if (mes.length === 1) m = mes[0]; else { sl = []; for (var i in mes) { if (IsInDict(mes[i].slice(-1) === "." ? mes[i].substring(0, mes[i].length - 1) : mes[i])) { sl.push(mes[i]) } } if (sl.length > 0) m = sl[0]; else m = mes[0] } if (res === "") { m = cap(m) } if (res.slice(-1) === ".") { m = cap(m) } } res += " " + m; if (ex !== "") res += ex } return res.trim() } function cap(e) { return e.charAt(0).toUpperCase() + e.slice(1) } tokens = { $: ["s"], "(": ["c"], 5: ["s"], "@": ["a"], 4: ["a", "for"], 3: ["e"], "+": ["t"], "#": ["h"], teh: ["the"], "'d": ["ed"], pwnd: ["pwned"], pwnt: ["pwned"], k: ["ok"], kk: ["ok"], 0: ["o"], y: ["why"], txt: ["text"], dafuq: ["what the f**k"], "/\\": ["a"], "^": ["a"], "\\/": ["v"], d00d: ["dude"], n00b: ["newbie"], "\\/\\/": ["w"], 8: ["b", "ate"], "|_|": ["u"], "|-|": ["h"], "Я": ["r"], j00: ["you"], joo: ["you"], vv: ["w"], tomoz: ["tomorrow"], "|<": ["k"], "[)": ["d"], "|)": ["d"], "<3": ["love"], "><": ["x"], 10100111001: ["leet"], 2: ["to", "too"], ur: ["your", "you're"], u: ["you"], x: ["ks", "cks"], z: ["s"], 1: ["i", "l"], "!": ["i"], c: ["see", "sea"], b: ["be", "bee"], "&": ["and", "anned", "ant"], 7: ["and", "anned", "ant", "t"] }; et = { eno: "!", nevele: "!!", 1: "!", "!": "!" }
取消高尔夫:
tokens={
'$':['s'],'(':['c'],'5':['s'],'@':['a'],'4':['a','for'],'3':['e'],'+':['t'],'#':['h'],'teh':['the'],"'d":['ed'],'pwnd':['pwned'],
'pwnt':['pwned'],'k':['ok'],'kk':['ok'],'0':['o'],'y':['why'],'txt':['text'],'dafuq':['what the f**k'],
'/\\':['a'],'^':['a'],'\\/':['v'],'d00d':['dude'],'n00b':['newbie'],
'\\/\\/':['w'],'8':['b','ate'],'|_|':['u'],'|-|':['h'],'Я':['r'],'j00':['you'],
'joo':['you'],'vv':['w'],'tomoz':['tomorrow'],'|<':['k'],'[)':['d'],'|)':['d'],'<3':['love'],
'><':['x'],'10100111001':['leet'],'2':['to','too'],'ur':["your","you're"],
'u':['you'],'x':['ks','cks'],'z':['s'],'1':['i','l'],'!':['i'],'c':['see','sea'],
'b':['be','bee'],'&':['and','anned','ant'],'7':['and','anned','ant','t']}
var excTokens = {'eno':'!','nevele':'!!','1':'!','!':'!'}
function IsInDict(word)
{
return (W[word]);
}
function translate(input) {
var words = input.split(" ");
var result = "";
for (var i in words) {
var exclamations = "";
function parseExclamations(s, prev, exclamationFound) {
var matchFound = false;
for (var j = 1; j <= s.length; j++) {
var hasExclamation = (s.substring(0, j) === "!") || exclamationFound;
var currentToken = excTokens[s.substring(0, j)];
var remaining = s.substring(j);
if (currentToken) {
matchFound = true;
if (remaining.length === 0) {
if (hasExclamation) {
exclamations = prev + currentToken;
words[i] = "";//word only had exclamations in it so dont parse the rest of it
}
}
else
parseExclamations(remaining, prev + currentToken, hasExclamation);
}
}
if (exclamationFound && !matchFound && prev) {
exclamations = prev;
words[i] = s.split("").reverse().join("");//reverse back again
}
}
var reverseWord = words[i].split("").reverse().join("");
parseExclamations(reverseWord, "", false);
var matches = []
function parse(s, prev) {
for (var j = 1; j <= s.length; j++) {
var currentTokenArray = tokens[s.substring(0, j)];
var remaining = s.substring(j);
if (currentTokenArray) {
matchFound = true;
if (remaining.length === 0)
for (var k in currentTokenArray) {
matches.push(prev + currentTokenArray[k]);
}
else
for (var k in currentTokenArray)
parse(remaining, prev + currentTokenArray[k]);
}
}
if (s.length > 1)
parse(s.substring(1), prev + s.substring(0, 1));
else {
matches.push(prev + s);
}
}
var match = "";
if (words[i] !== "") {
parse(words[i].toLowerCase(), "");
//check the dictionary
if (matches.length === 1)
match = matches[0];
else {
var shortlist = [];
for (var j in matches) {
//check dictionary. allow for a full stop at the end of the word
var isInDict = IsInDict(matches[j].slice(-1) === "." ? matches[j].substring(0, matches[j].length - 1) : matches[j]);
if (isInDict) {
shortlist.push(matches[j]);
}
}
if (shortlist.length > 0)
match = shortlist[0];
else
match = matches[0];
}
if (result === "") {
match = cap(match);
}
if (result.slice(-1) === ".") {
match = cap(match);
}
}
result += " " + match;
if (exclamations !== "")
result += exclamations;
}
return result.trim();
}
function cap(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
检测结果:
- |-| 3 15 $ | _ |(##n00b ====>他真是个新手
- @ 1 // 4Y5 p0 $ + ur n3VV qu35710nz 1n teh $&80x ====>始终在沙盒中发布新问题
- !!! 1 !! 1 ====> !!!!!!!
- !!!一!====> !!!!!
- !十一====> !!!
- teh !!! 1 !! 1 ====> The !!!!!!!
- !!一个!====> The !!!!!
- 十一!====> !!!
- !!! 1 !! 1 ====> The !!!!!!!
- qu35710nz!1!====>问题!!!
- +357 +357。735+ ====>测试测试。测试
- &31!73#4(KER $ WR0 + 3 83773R L!K3 +#!5 7#@ N 2D @ Y ====>像这样的精英黑客比今天写的更好
笔记:
字典是一个单独的javascript文件,其中的对象W包含所有单词。这仅包含运行相关测试所需的单词。