結果
問題 | No.9001 標準入出力の練習問題(テスト用) |
ユーザー | らっしー(raccy) |
提出日時 | 2015-11-15 12:48:50 |
言語 | JavaScript (node v21.7.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 19,891 bytes |
コンパイル時間 | 43 ms |
コンパイル使用メモリ | 5,376 KB |
実行使用メモリ | 40,320 KB |
最終ジャッジ日時 | 2024-10-12 23:35:03 |
合計ジャッジ時間 | 664 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ソースコード
/* PureScript module Main where import Prelude import Control.Monad.Eff import Control.Monad.Eff.Console import Node.ReadLine import Data.String (split) import Data.Int (fromString) import Data.Foldable (sum) import Data.Array (catMaybes) main :: forall eff. Eff (console :: CONSOLE | eff) Interface main = do interface1 <- createInterface noCompletion setLineHandler interface1 $ \line1 -> do close interface1 interface2 <- createInterface noCompletion setLineHandler interface2 $ \line2 -> do log $ show (sumFromString line1) ++ " " ++ line2 close interface2 sumFromString :: String -> Int sumFromString s = sum $ catMaybes $ fromString <$> split " " s */ // Generated by psc-bundle 0.7.5.3 var PS = { }; (function(exports) { /* global exports */ "use strict"; // module Control.Monad.Eff exports.returnE = function (a) { return function () { return a; }; }; exports.bindE = function (a) { return function (f) { return function () { return f(a())(); }; }; }; })(PS["Control.Monad.Eff"] = PS["Control.Monad.Eff"] || {}); (function(exports) { /* global exports */ "use strict"; // module Prelude //- Functor -------------------------------------------------------------------- exports.arrayMap = function (f) { return function (arr) { var l = arr.length; var result = new Array(l); for (var i = 0; i < l; i++) { result[i] = f(arr[i]); } return result; }; }; //- Bind ----------------------------------------------------------------------- exports.arrayBind = function (arr) { return function (f) { var result = []; for (var i = 0, l = arr.length; i < l; i++) { Array.prototype.push.apply(result, f(arr[i])); } return result; }; }; //- Semiring ------------------------------------------------------------------- exports.intAdd = function (x) { return function (y) { /* jshint bitwise: false */ return x + y | 0; }; }; exports.intMul = function (x) { return function (y) { /* jshint bitwise: false */ return x * y | 0; }; }; //- Show ----------------------------------------------------------------------- exports.showIntImpl = function (n) { return n.toString(); }; })(PS["Prelude"] = PS["Prelude"] || {}); (function(exports) { // Generated by psc version 0.7.5.3 "use strict"; var $foreign = PS["Prelude"]; var Semigroupoid = function (compose) { this.compose = compose; }; var Category = function (__superclass_Prelude$dotSemigroupoid_0, id) { this["__superclass_Prelude.Semigroupoid_0"] = __superclass_Prelude$dotSemigroupoid_0; this.id = id; }; var Functor = function (map) { this.map = map; }; var Apply = function (__superclass_Prelude$dotFunctor_0, apply) { this["__superclass_Prelude.Functor_0"] = __superclass_Prelude$dotFunctor_0; this.apply = apply; }; var Applicative = function (__superclass_Prelude$dotApply_0, pure) { this["__superclass_Prelude.Apply_0"] = __superclass_Prelude$dotApply_0; this.pure = pure; }; var Bind = function (__superclass_Prelude$dotApply_0, bind) { this["__superclass_Prelude.Apply_0"] = __superclass_Prelude$dotApply_0; this.bind = bind; }; var Monad = function (__superclass_Prelude$dotApplicative_0, __superclass_Prelude$dotBind_1) { this["__superclass_Prelude.Applicative_0"] = __superclass_Prelude$dotApplicative_0; this["__superclass_Prelude.Bind_1"] = __superclass_Prelude$dotBind_1; }; var Semiring = function (add, mul, one, zero) { this.add = add; this.mul = mul; this.one = one; this.zero = zero; }; var Show = function (show) { this.show = show; }; var zero = function (dict) { return dict.zero; }; var showInt = new Show($foreign.showIntImpl); var show = function (dict) { return dict.show; }; var semiringInt = new Semiring($foreign.intAdd, $foreign.intMul, 1, 0); var semigroupoidFn = new Semigroupoid(function (f) { return function (g) { return function (x) { return f(g(x)); }; }; }); var pure = function (dict) { return dict.pure; }; var $$return = function (__dict_Applicative_2) { return pure(__dict_Applicative_2); }; var one = function (dict) { return dict.one; }; var mul = function (dict) { return dict.mul; }; var map = function (dict) { return dict.map; }; var $less$dollar$greater = function (__dict_Functor_5) { return map(__dict_Functor_5); }; var id = function (dict) { return dict.id; }; var functorArray = new Functor($foreign.arrayMap); var flip = function (f) { return function (b) { return function (a) { return f(a)(b); }; }; }; var compose = function (dict) { return dict.compose; }; var categoryFn = new Category(function () { return semigroupoidFn; }, function (x) { return x; }); var bind = function (dict) { return dict.bind; }; var apply = function (dict) { return dict.apply; }; var $less$times$greater = function (__dict_Apply_25) { return apply(__dict_Apply_25); }; var liftA1 = function (__dict_Applicative_26) { return function (f) { return function (a) { return $less$times$greater(__dict_Applicative_26["__superclass_Prelude.Apply_0"]())(pure(__dict_Applicative_26)(f))(a); }; }; }; var append = function (dict) { return dict.append; }; var $less$greater = function (__dict_Semigroup_28) { return append(__dict_Semigroup_28); }; var ap = function (__dict_Monad_30) { return function (f) { return function (a) { return bind(__dict_Monad_30["__superclass_Prelude.Bind_1"]())(f)(function (_2) { return bind(__dict_Monad_30["__superclass_Prelude.Bind_1"]())(a)(function (_1) { return $$return(__dict_Monad_30["__superclass_Prelude.Applicative_0"]())(_2(_1)); }); }); }; }; }; var monadArray = new Monad(function () { return applicativeArray; }, function () { return bindArray; }); var bindArray = new Bind(function () { return applyArray; }, $foreign.arrayBind); var applyArray = new Apply(function () { return functorArray; }, ap(monadArray)); var applicativeArray = new Applicative(function () { return applyArray; }, function (x) { return [ x ]; }); var add = function (dict) { return dict.add; }; var $plus = function (__dict_Semiring_31) { return add(__dict_Semiring_31); }; exports["Show"] = Show; exports["Semiring"] = Semiring; exports["Monad"] = Monad; exports["Bind"] = Bind; exports["Applicative"] = Applicative; exports["Apply"] = Apply; exports["Functor"] = Functor; exports["Category"] = Category; exports["Semigroupoid"] = Semigroupoid; exports["show"] = show; exports["+"] = $plus; exports["one"] = one; exports["mul"] = mul; exports["zero"] = zero; exports["add"] = add; exports["<>"] = $less$greater; exports["append"] = append; exports["ap"] = ap; exports["return"] = $$return; exports["bind"] = bind; exports["liftA1"] = liftA1; exports["pure"] = pure; exports["apply"] = apply; exports["<$>"] = $less$dollar$greater; exports["map"] = map; exports["id"] = id; exports["compose"] = compose; exports["flip"] = flip; exports["semigroupoidFn"] = semigroupoidFn; exports["categoryFn"] = categoryFn; exports["functorArray"] = functorArray; exports["applyArray"] = applyArray; exports["applicativeArray"] = applicativeArray; exports["bindArray"] = bindArray; exports["monadArray"] = monadArray; exports["semiringInt"] = semiringInt; exports["showInt"] = showInt;; })(PS["Prelude"] = PS["Prelude"] || {}); (function(exports) { // Generated by psc version 0.7.5.3 "use strict"; var $foreign = PS["Control.Monad.Eff"]; var Prelude = PS["Prelude"]; var monadEff = new Prelude.Monad(function () { return applicativeEff; }, function () { return bindEff; }); var bindEff = new Prelude.Bind(function () { return applyEff; }, $foreign.bindE); var applyEff = new Prelude.Apply(function () { return functorEff; }, Prelude.ap(monadEff)); var applicativeEff = new Prelude.Applicative(function () { return applyEff; }, $foreign.returnE); var functorEff = new Prelude.Functor(Prelude.liftA1(applicativeEff)); exports["functorEff"] = functorEff; exports["applyEff"] = applyEff; exports["applicativeEff"] = applicativeEff; exports["bindEff"] = bindEff; exports["monadEff"] = monadEff;; })(PS["Control.Monad.Eff"] = PS["Control.Monad.Eff"] || {}); (function(exports) { /* global exports, console */ "use strict"; // module Control.Monad.Eff.Console exports.log = function (s) { return function () { console.log(s); return {}; }; }; })(PS["Control.Monad.Eff.Console"] = PS["Control.Monad.Eff.Console"] || {}); (function(exports) { // Generated by psc version 0.7.5.3 "use strict"; var $foreign = PS["Control.Monad.Eff.Console"]; var Prelude = PS["Prelude"]; var Control_Monad_Eff = PS["Control.Monad.Eff"]; exports["log"] = $foreign.log;; })(PS["Control.Monad.Eff.Console"] = PS["Control.Monad.Eff.Console"] || {}); (function(exports) { /* global exports */ "use strict"; // module Data.Foldable exports.foldrArray = function (f) { return function (init) { return function (xs) { var acc = init; var len = xs.length; for (var i = len - 1; i >= 0; i--) { acc = f(xs[i])(acc); } return acc; }; }; }; exports.foldlArray = function (f) { return function (init) { return function (xs) { var acc = init; var len = xs.length; for (var i = 0; i < len; i++) { acc = f(acc)(xs[i]); } return acc; }; }; }; })(PS["Data.Foldable"] = PS["Data.Foldable"] || {}); (function(exports) { // Generated by psc version 0.7.5.3 "use strict"; var Prelude = PS["Prelude"]; var mempty = function (dict) { return dict.mempty; }; exports["mempty"] = mempty;; })(PS["Data.Monoid"] = PS["Data.Monoid"] || {}); (function(exports) { // Generated by psc version 0.7.5.3 "use strict"; var Prelude = PS["Prelude"]; var Control_Alt = PS["Control.Alt"]; var Control_Alternative = PS["Control.Alternative"]; var Control_Extend = PS["Control.Extend"]; var Control_MonadPlus = PS["Control.MonadPlus"]; var Control_Plus = PS["Control.Plus"]; var Data_Functor_Invariant = PS["Data.Functor.Invariant"]; var Data_Monoid = PS["Data.Monoid"]; var Nothing = (function () { function Nothing() { }; Nothing.value = new Nothing(); return Nothing; })(); var Just = (function () { function Just(value0) { this.value0 = value0; }; Just.create = function (value0) { return new Just(value0); }; return Just; })(); var maybe = function (b) { return function (f) { return function (_0) { if (_0 instanceof Nothing) { return b; }; if (_0 instanceof Just) { return f(_0.value0); }; throw new Error("Failed pattern match at Data.Maybe line 26, column 1 - line 27, column 1: " + [ b.constructor.name, f.constructor.name, _0.constructor.name ]); }; }; }; exports["Nothing"] = Nothing; exports["Just"] = Just; exports["maybe"] = maybe;; })(PS["Data.Maybe"] = PS["Data.Maybe"] || {}); (function(exports) { // Generated by psc version 0.7.5.3 "use strict"; var $foreign = PS["Data.Foldable"]; var Prelude = PS["Prelude"]; var Control_Apply = PS["Control.Apply"]; var Data_Maybe = PS["Data.Maybe"]; var Data_Maybe_First = PS["Data.Maybe.First"]; var Data_Maybe_Last = PS["Data.Maybe.Last"]; var Data_Monoid = PS["Data.Monoid"]; var Data_Monoid_Additive = PS["Data.Monoid.Additive"]; var Data_Monoid_Conj = PS["Data.Monoid.Conj"]; var Data_Monoid_Disj = PS["Data.Monoid.Disj"]; var Data_Monoid_Dual = PS["Data.Monoid.Dual"]; var Data_Monoid_Endo = PS["Data.Monoid.Endo"]; var Data_Monoid_Multiplicative = PS["Data.Monoid.Multiplicative"]; var Foldable = function (foldMap, foldl, foldr) { this.foldMap = foldMap; this.foldl = foldl; this.foldr = foldr; }; var foldr = function (dict) { return dict.foldr; }; var foldl = function (dict) { return dict.foldl; }; var sum = function (__dict_Foldable_12) { return function (__dict_Semiring_13) { return foldl(__dict_Foldable_12)(Prelude["+"](__dict_Semiring_13))(Prelude.zero(__dict_Semiring_13)); }; }; var foldMapDefaultR = function (__dict_Foldable_20) { return function (__dict_Monoid_21) { return function (f) { return function (xs) { return foldr(__dict_Foldable_20)(function (x) { return function (acc) { return Prelude["<>"](__dict_Monoid_21["__superclass_Prelude.Semigroup_0"]())(f(x))(acc); }; })(Data_Monoid.mempty(__dict_Monoid_21))(xs); }; }; }; }; var foldableArray = new Foldable(function (__dict_Monoid_22) { return foldMapDefaultR(foldableArray)(__dict_Monoid_22); }, $foreign.foldlArray, $foreign.foldrArray); var foldMap = function (dict) { return dict.foldMap; }; exports["Foldable"] = Foldable; exports["sum"] = sum; exports["foldMapDefaultR"] = foldMapDefaultR; exports["foldMap"] = foldMap; exports["foldl"] = foldl; exports["foldr"] = foldr; exports["foldableArray"] = foldableArray;; })(PS["Data.Foldable"] = PS["Data.Foldable"] || {}); (function(exports) { // Generated by psc version 0.7.5.3 "use strict"; var $foreign = PS["Data.Array"]; var Prelude = PS["Prelude"]; var Control_Alt = PS["Control.Alt"]; var Control_Alternative = PS["Control.Alternative"]; var Control_Lazy = PS["Control.Lazy"]; var Control_MonadPlus = PS["Control.MonadPlus"]; var Control_Plus = PS["Control.Plus"]; var Data_Foldable = PS["Data.Foldable"]; var Data_Functor_Invariant = PS["Data.Functor.Invariant"]; var Data_Maybe = PS["Data.Maybe"]; var Data_Monoid = PS["Data.Monoid"]; var Data_Traversable = PS["Data.Traversable"]; var Data_Tuple = PS["Data.Tuple"]; var Data_Maybe_Unsafe = PS["Data.Maybe.Unsafe"]; var singleton = function (a) { return [ a ]; }; var concatMap = Prelude.flip(Prelude.bind(Prelude.bindArray)); var mapMaybe = function (f) { return concatMap(function (_48) { return Data_Maybe.maybe([ ])(singleton)(f(_48)); }); }; var catMaybes = mapMaybe(Prelude.id(Prelude.categoryFn)); exports["catMaybes"] = catMaybes; exports["mapMaybe"] = mapMaybe; exports["concatMap"] = concatMap; exports["singleton"] = singleton;; })(PS["Data.Array"] = PS["Data.Array"] || {}); (function(exports) { /* global exports */ "use strict"; exports.fromStringImpl = function (just) { return function (nothing) { return function (s) { /* jshint bitwise: false */ var i = parseFloat(s); return (i | 0) === i ? just(i) : nothing; }; }; }; })(PS["Data.Int"] = PS["Data.Int"] || {}); (function(exports) { // Generated by psc version 0.7.5.3 "use strict"; var $foreign = PS["Data.Int"]; var Prelude = PS["Prelude"]; var Data_Int_Bits = PS["Data.Int.Bits"]; var Data_Maybe = PS["Data.Maybe"]; var Data_Maybe_Unsafe = PS["Data.Maybe.Unsafe"]; var $$Math = PS["Math"]; var fromString = $foreign.fromStringImpl(Data_Maybe.Just.create)(Data_Maybe.Nothing.value); exports["fromString"] = fromString;; })(PS["Data.Int"] = PS["Data.Int"] || {}); (function(exports) { /* global exports */ "use strict"; exports.split = function (sep) { return function (s) { return s.split(sep); }; }; })(PS["Data.String"] = PS["Data.String"] || {}); (function(exports) { // Generated by psc version 0.7.5.3 "use strict"; var $foreign = PS["Data.String"]; var Prelude = PS["Prelude"]; var Data_Char = PS["Data.Char"]; var Data_Maybe = PS["Data.Maybe"]; var Data_Monoid = PS["Data.Monoid"]; var Data_String_Unsafe = PS["Data.String.Unsafe"]; exports["split"] = $foreign.split;; })(PS["Data.String"] = PS["Data.String"] || {}); (function(exports) { /* global exports */ "use strict"; // module Node.ReadLine exports.setLineHandler = function(readline) { return function(callback) { return function() { readline.removeAllListeners('line'); readline.on('line', function(line) { callback(line)(); }); return readline; }; }; }; exports.createInterface = function(completer) { return function() { var readline = require('readline'); return readline.createInterface({ input: process.stdin, output: process.stdout, completer: function(line) { var res = completer(line)(); return [res.completions, res.suffix]; } }); }; }; exports.close = function(readline) { return function() { readline.close(); return readline; }; }; })(PS["Node.ReadLine"] = PS["Node.ReadLine"] || {}); (function(exports) { // Generated by psc version 0.7.5.3 "use strict"; var $foreign = PS["Node.ReadLine"]; var Prelude = PS["Prelude"]; var Control_Monad_Eff = PS["Control.Monad.Eff"]; var Control_Monad_Eff_Console = PS["Control.Monad.Eff.Console"]; var noCompletion = function (s) { return Prelude["return"](Control_Monad_Eff.applicativeEff)({ completions: [ ], matched: s }); }; exports["noCompletion"] = noCompletion; exports["close"] = $foreign.close; exports["createInterface"] = $foreign.createInterface; exports["setLineHandler"] = $foreign.setLineHandler;; })(PS["Node.ReadLine"] = PS["Node.ReadLine"] || {}); (function(exports) { // Generated by psc version 0.7.5.3 "use strict"; var Prelude = PS["Prelude"]; var Control_Monad_Eff = PS["Control.Monad.Eff"]; var Control_Monad_Eff_Console = PS["Control.Monad.Eff.Console"]; var Node_ReadLine = PS["Node.ReadLine"]; var Data_String = PS["Data.String"]; var Data_Int = PS["Data.Int"]; var Data_Foldable = PS["Data.Foldable"]; var Data_Array = PS["Data.Array"]; var sumFromString = function (s) { return Data_Foldable.sum(Data_Foldable.foldableArray)(Prelude.semiringInt)(Data_Array.catMaybes(Prelude["<$>"](Prelude.functorArray)(Data_Int.fromString)(Data_String.split(" ")(s)))); }; var main = function __do() { var _1 = Node_ReadLine.createInterface(Node_ReadLine.noCompletion)(); return Node_ReadLine.setLineHandler(_1)(function (line1) { return function __do() { Node_ReadLine.close(_1)(); var _0 = Node_ReadLine.createInterface(Node_ReadLine.noCompletion)(); return Node_ReadLine.setLineHandler(_0)(function (line2) { return function __do() { Control_Monad_Eff_Console.log(Prelude.show(Prelude.showInt)(sumFromString(line1)) + (" " + line2))(); return Node_ReadLine.close(_0)(); }; })(); }; })(); }; exports["sumFromString"] = sumFromString; exports["main"] = main;; })(PS["Main"] = PS["Main"] || {}); PS["Main"].main();