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

問題 #2 - 回答 #155

+ + +

Base32

+

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

+

回答 #155

+

+ hanhan1978 が 2024-03-09 15:19:33 に投稿 +

+

コード

+

+ 275 byte +

+
while($l=rtrim(fgets(STDIN))){$b=$r='';
+foreach(str_split($l) as $c) $b.=str_pad(decbin(ord($c)),8,0,0);
+foreach(str_split($b,5) as $s) $r.='ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'[bindec(str_pad($s,5,"0"))];
+$r.=@str_repeat("=", strlen($b)%40?8-(strlen($b)%40)/5:0);echo $r,"\n";}
+

実行結果

+
+
+
+ ステータス: OK +
+
+

テストケース 1

+
+ ステータス: OK +
+

標準出力

+
NBXWOZI=
+OBUXS3Y=
+MZ2WOYI=
+
+
+

標準エラー出力

+

+
+

テストケース 2

+
+ ステータス: OK +
+

標準出力

+
4OAYNY4BRPRYFCXDQGX6HAMS
+4OA2VY4BRTRYFCPDQGDOHAMX
+4OBI7Y4BTHRYFCPDQKBOHANB
+
+
+

標準エラー出力

+

+
+

テストケース 3

+
+ ステータス: OK +
+

標準出力

+
GEZDGNBVGY3Q====
+GEZA====
+GEZDGNBVGY3TQOJQ
+GEZDGNBVGY3TQ===
+GEZDG===
+GEZDGNBV
+GEZDGNBVGY3TQOI=
+GEZDGNA=
+GE======
+GEZDGNBVGY======
+
+
+

標準エラー出力

+

+
+

テストケース 4

+
+ ステータス: OK +
+

標準出力

+
MEQGEIDD
+EAQOHAMC4OAYIIHDQGDCBY4BRAQOHAMK
+
+
+

標準エラー出力

+

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