From fbd4f2129ce8fe106391302896dd86e05b2f331b Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 5 Dec 2025 04:08:22 +0900 Subject: add files --- archive/q/base32/a/158/index.html | 116 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 archive/q/base32/a/158/index.html (limited to 'archive/q/base32/a/158/index.html') diff --git a/archive/q/base32/a/158/index.html b/archive/q/base32/a/158/index.html new file mode 100644 index 0000000..f8f394a --- /dev/null +++ b/archive/q/base32/a/158/index.html @@ -0,0 +1,116 @@ + + + + + 問題 #2 - 回答 #158 | Albatross.PHP + + + + + +
+ +
+
+

問題 #2 - 回答 #158

+ + +

Base32

+

+ RFC 4648 で定義された Base32 エンコーディングを実装してください。 +標準入力から与えられる各行に対し、Base32 エンコードをおこなった文字列を標準出力へ改行区切りで出力してください。 +なお、アルファベットの出力には大文字を用いてください。 +

+

回答 #158

+

+ notchman が 2024-03-09 15:54:51 に投稿 +

+

コード

+

+ 362 byte +

+
while ($line = rtrim(fgets(STDIN))) {
+  echo array_reduce(str_split($b = '', strlen($line)) && array_map(function($c) use(&$b) { $b .= sprintf('%08b', ord($c)); }, str_split($line)) ? str_split($b, 5) : [], function($c, $n) { return $c.TABLE[bindec(str_pad($n, 5, '0', STR_PAD_RIGHT))]; }, '') . str_repeat('=', [0, 6, 4, 3, 1][strlen($b) % 40 / 8]) . PHP_EOL;
+}
+

実行結果

+
+
+
+ ステータス: 失敗 +
+
+

テストケース 1

+
+ ステータス: 不正解 +
+

標準出力

+

+
+
+
+
+

標準エラー出力

+

+
+

テストケース 2

+
+ ステータス: 不正解 +
+

標準出力

+

+
+
+
+
+

標準エラー出力

+

+
+

テストケース 3

+
+ ステータス: 不正解 +
+

標準出力

+

+
+
+
+
+
+
+
+
+
+
+
+

標準エラー出力

+

+
+

テストケース 4

+
+ ステータス: 不正解 +
+

標準出力

+

+
+
+
+

標準エラー出力

+

+
+
+ +
+ + + -- cgit v1.2.3-70-g09d2