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

問題 #2

+ + +

Base32

+

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

+

実装例

+
const TABLE = [
+  'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
+  'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
+  'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
+  'Y', 'Z', '2', '3', '4', '5', '6', '7',
+];
+while ($line = fgets(STDIN)) {
+  $line = rtrim($line);
+  $bits = '';
+  for ($i = 0; $i < strlen($line); $i++) {
+    $bits .= str_pad(base_convert(strval(ord($line[$i])), 10, 2), 8, '0', STR_PAD_LEFT);
+  }
+  $base32 = '';
+  foreach (str_split($bits, 5) as $b) {
+    $base32 .= TABLE[base_convert(str_pad($b, 5, '0'), 2, 10)];
+  }
+  $base32 .= match (strlen($bits) % 40) {
+    8 => '======',
+    16 => '====',
+    24 => '===',
+    32 => '=',
+    default => '',
+  };
+  echo $base32, PHP_EOL;
+}
+

ランキング

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ランクID作者サイズ投稿日時
1 + #70 + takaram225 byte2024-03-08 12:40:28
2 + #62 + nsfisis (staff)235 byte2024-03-08 05:25:41
3 + #137 + basi250 byte2024-03-09 04:27:40
4 + #85 + m3m0r7262 byte2024-03-08 14:57:05
5 + #155 + hanhan1978275 byte2024-03-09 15:19:33
6 + #135 + tadsan (staff)276 byte2024-03-09 04:24:05
7 + #157 + notchman322 byte2024-03-09 15:53:40
8 + #52 + yamamoto-hiroya333 byte2024-03-08 00:18:57
9 + #127 + azuki-penguin355 byte2024-03-09 03:21:55
10 + #57 + kunikiya399 byte2024-03-08 02:34:49
11 + #42 + rinchoku447 byte2024-03-07 23:59:24
12 + #150 + tsbkw461 byte2024-03-09 11:41:14
13 + #2 + blue-goheimochi (staff)677 byte2024-03-06 08:24:32
14 + #3 + muno92 (staff)677 byte2024-03-06 08:42:30
15 + #140 + masnmt677 byte2024-03-09 04:52:12
16 + #141 + k-kuwata677 byte2024-03-09 08:36:45
17 + #151 + ticknical677 byte2024-03-09 14:38:16
+
+ + +
+

+ すべての回答を見る +

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