Last active
January 10, 2023 13:08
-
-
Save omas-public/7923acfd0b41518f092568521b31ba6a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const identity = v => v | |
const join = (sep = '\n') => array => array.join(sep) | |
const split = (sep = ' ') => string => string.split(sep) | |
const inputs = (file = '/dev/stdin') => { | |
const stream = require('fs').readFileSync(file, 'utf-8').trim() | |
const toArray = sep => fn => iter => Array.from(split(sep)(iter), fn) | |
return { | |
readCols: (fn = identity) => toArray(' ')(fn)(stream), | |
readRows: (fn = identity) => toArray('\n')(fn)(stream), | |
readStream: (fn = identity) => fn(stream), | |
readMatrix: (fn = identity) => toArray('\n')(identity)(stream) | |
.map(toArray(' ')(fn)) | |
} | |
} | |
const outputs = v => { | |
const _print = fn => v => console.log(fn(v)) | |
return { | |
toLine: () => _print(identity)(v), | |
toCols: () => _print(join(' '))(v), | |
toRows: () => _print(join('\n'))(v), | |
toJSON: () => _print(JSON.stringify)(v), | |
toMatrix: () => _print(join('\n'))(v.map(join(' '))) | |
} | |
} | |
// 即時実行関数(main) | |
(() => { | |
// define function | |
const fn = (n, p, m, q) => { | |
// ここに処理を書く | |
const autographsCosts = n * p | |
const penCosts = Math.ceil(n / m) * q | |
return autographsCosts + penCosts | |
} | |
// declare varriable | |
const [[n, p], [m, q]] = inputs().readMatrix(Number) | |
// processing | |
const result = fn(n, p, m, q) | |
// display | |
outputs(result).Line() | |
})() |
This file contains hidden or 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
100 110 | |
20 200 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment