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/54/index.html | 132 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 archive/q/base32/a/54/index.html (limited to 'archive/q/base32/a/54/index.html') diff --git a/archive/q/base32/a/54/index.html b/archive/q/base32/a/54/index.html new file mode 100644 index 0000000..a13c1d8 --- /dev/null +++ b/archive/q/base32/a/54/index.html @@ -0,0 +1,132 @@ + + + + + 問題 #2 - 回答 #54 | Albatross.PHP + + + + + +
+ +
+
+

問題 #2 - 回答 #54

+ + +

Base32

+

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

+

回答 #54

+

+ kunikiya が 2024-03-08 02:26:59 に投稿 +

+

コード

+

+ 484 byte +

+
$t = array_merge(range('A','Z'),range(2,7));
+while ($line = rtrim(fgets(STDIN))) {
+  $bi = '';
+  for ($i = 0; $i < strlen($line); $i++) {
+    $bi .= str_pad(base_convert(strval(ord($line[$i])), 10, 2), 8, '0', STR_PAD_LEFT);
+  }
+  $b = '';
+  foreach (str_split($bi, 5) as $b) {
+    $b .= $t[base_convert(str_pad($b, 5, '0'), 2, 10)];
+  }
+  $b .= match (strlen($bi) % 40) {
+    8 => '======',
+    16 => '====',
+    24 => '===',
+    32 => '=',
+    default => '',
+  };
+  echo $b, "\n";
+}
+

実行結果

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

テストケース 1

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

標準出力

+
01I=
+11Y=
+01I=
+
+
+

標準エラー出力

+

+
+

テストケース 2

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

標準出力

+
10010S
+10111X
+00001B
+
+
+

標準エラー出力

+

+
+

テストケース 3

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

標準出力

+
1Q====
+0A====
+10000Q
+1000Q===
+0011G===
+10101V
+01I=
+00A=
+001E======
+110Y======
+
+
+

標準エラー出力

+

+
+

テストケース 4

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

標準出力

+
00011D
+01010K
+
+
+

標準エラー出力

+

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