Created
March 6, 2015 10:02
-
-
Save shunjikonishi/af583a4766f3406fb133 to your computer and use it in GitHub Desktop.
2015/03/06 DeNA問題とVasily問題の回答
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var STR = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_!+-/.:"; | |
var INPUT = "JfnAmrOmaTrRr:lmiCLmgCUpmoRRF/yycf:T!ZC-yuFyLfZLUrRyORUcf:ROy-fOOTlfiLC-iCU:cfLy"; | |
var LOOP = 100000; | |
function adjust(n) { | |
while (n > 58) { | |
n -= 59; | |
} | |
while (n < 0) { | |
n += 59; | |
} | |
return n; | |
} | |
function D_(n) { | |
return n * 2 + 1; | |
} | |
function e_(n) { | |
return n * 2 - 2; | |
} | |
function n_(n) { | |
return n * 2 + 4; | |
} | |
function a_(n) { | |
return n * 2 - 8; | |
} | |
function strToArray(s) { | |
var ret = []; | |
for (var i=0; i<s.length; i++) { | |
ret.push(STR.indexOf(s.charAt(i))); | |
} | |
return ret; | |
} | |
function arrayToStr(array) { | |
var ret = ""; | |
for (var i=0; i<array.length; i++) { | |
ret += STR.charAt(array[i]); | |
} | |
return ret; | |
} | |
function calc(input, loop) { | |
var rules = [D_, e_, n_, a_]; | |
var array = strToArray(input), | |
idx = 0; | |
for (var i=0; i<loop; i++) { | |
func = rules[idx++]; | |
for (var j=0; j<array.length; j++) { | |
var n = adjust(func(array[j])); | |
array[j] = n; | |
} | |
if (idx >= rules.length) { | |
idx = 0; | |
} | |
} | |
return arrayToStr(array); | |
} | |
console.log(calc(INPUT, LOOP)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var | |
env = require("jsdom").env, | |
najax = require("najax"), | |
url = "http://item.iqon.jp/lcat11/page-7/"; | |
function getId($item) { | |
var | |
str = $item.find("a:first").attr("href"), | |
array = str.split("/"); | |
return array.length >= 2 ? array[array.length - 2] : null; | |
} | |
function getName($item) { | |
return $item.find(".item-box-info-name").text(); | |
} | |
function getPrice($item) { | |
var ret = $item.find(".item-box-info-price-before").text(); | |
if (!ret) { | |
ret = $item.find(".item-box-info-price").text(); | |
} | |
return ret.replace(/[\\¥,]/g, ''); | |
} | |
function getSalePrice($item) { | |
var ret = $item.find(".item-box-info-price-sale").text(); | |
if (ret) { | |
ret = ret.replace(/[\\¥,]/g, ''); | |
} | |
return ret; | |
} | |
function getBrandName($item) { | |
return $item.find(".item-box-brand a").text(); | |
} | |
function getImageUrl($item) { | |
return $item.find("img").attr("data-original"); | |
} | |
function process($) { | |
var $items = $.find(".item-box"); | |
$items.forEach(function(item) { | |
var | |
$item = $(item), | |
id = getId($item), | |
ret = []; | |
if (id) { | |
ret.push(id); | |
ret.push(getName($item)); | |
ret.push(getPrice($item)); | |
ret.push(getSalePrice($item)); | |
ret.push(getBrandName($item)); | |
ret.push(getImageUrl($item)); | |
console.log(ret.join(",")); | |
} | |
}); | |
} | |
najax({ | |
"type": "GET", | |
"url": url, | |
"success": function(data) { | |
env(data, function(errors, window) { | |
var $ = require("jquery")(window); | |
process($); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment