Last active
July 21, 2022 03:28
-
-
Save zakuroishikuro/65c9277b5df620d2492e9ca3b446532f to your computer and use it in GitHub Desktop.
PG BATTLE 2021 過去問 https://products.sint.co.jp/q_list_2021
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
/** | |
* ましゅまろ1 物理現象グラフィックバトル | |
* https://products.sint.co.jp/hubfs/resource/topsic/pgb2021/1_1.pdf | |
* | |
* 入出力は適当 (文字列 or 数値) | |
*/ | |
// 前提条件 (実行しない) | |
function premise(input) { | |
const [x, y, k] = input.split(/\s+/).map(s => parseInt(s)); | |
console.assert(1 <= x && y <= 1000); | |
console.assert(1 <= k && k < x * y); | |
} | |
// 処理 | |
function main(input) { | |
const [x, y, k] = input.split(/\s+/).map(s => parseInt(s)); | |
return y - k / x; | |
} | |
// テスト (ファイル名「*.test.js」にして「npx jest」または「npx jest --watchAll」) | |
test('solve examples', () => { | |
expect(main("3 5 8")).toBeCloseTo(7 / 3); | |
expect(main("161 803 39887")).toBeCloseTo(555.254658385093); | |
}); |
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
/** | |
* ましゅまろ2 ゼロのない整数 | |
* https://products.sint.co.jp/hubfs/resource/topsic/pgb2021/1_1.pdf | |
* | |
* 入出力は適当 (文字列 or 数値) | |
*/ | |
// 前提条件 (実行しない) | |
function premise(input) { | |
const x = BigInt(input); | |
console.assert(1n <= x && x <= 10n ** 100_000n); | |
} | |
// 処理 | |
function main(input) { | |
const zero = input.indexOf(0); // 数値にする必要なし | |
if (zero === -1) { | |
return input; | |
} else { | |
return input.slice(0, zero) + "1".repeat(input.length - zero); | |
} | |
} | |
// テスト (ファイル名「*.test.js」にして「npx jest」または「npx jest --watchAll」) | |
test('solve examples', () => { | |
expect(main("80")).toBe("81"); | |
expect(main("123456789123456789123456789123456789")).toBe("123456789123456789123456789123456789"); | |
expect(main("802")).toBe("811"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment