aboutsummaryrefslogtreecommitdiffhomepage
path: root/archive/q/base32/a/144/index.html
blob: a7a150b40b822e79be9e1a3d857b384418898742 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>問題 #2 - 回答 #144 | Albatross.PHP</title>
    <link rel="stylesheet" href="../../../../assets/index.css">
    <link rel="icon" type="image/svg+xml" href="../../../../assets/favicon.svg">
    <script type="module" src="../../../../assets/index.js"></script>
  </head>
  <body>
    <header class="container">
      <nav class="navbar">
        <a class="navbar-brand" href="../../../../index.html">Albatross.PHP</a>
      </nav>
    </header>
    <main class="container mt-5">
      <h1 class="mb-4">問題 #2 - 回答 #144</h1>
        <nav>
    <ol class="breadcrumb">
      <li class="breadcrumb-item"><a href="../../../../index.html">問題一覧</a></li>
      <li class="breadcrumb-item"><a href="../../index.html">Base32</a></li>
      <li class="breadcrumb-item"><a href="../index.html">回答一覧</a></li>
      <li class="breadcrumb-item active">#144</li>
    </ol>
  </nav>

  <h2>Base32</h2>
  <p>
    RFC 4648 で定義された Base32 エンコーディングを実装してください。
標準入力から与えられる各行に対し、Base32 エンコードをおこなった文字列を標準出力へ改行区切りで出力してください。
なお、アルファベットの出力には大文字を用いてください。
  </p>
  <h2>回答 #144</h2>
  <p>
    tsbkw が 2024-03-09 11:04:03 に投稿
  </p>
  <h2>コード</h2>
  <p>
    431 byte
  </p>
  <pre><code class="hljs language-php">const TABLE = [&#039;A&#039;,&#039;B&#039;,&#039;C&#039;,&#039;D&#039;,&#039;E&#039;,&#039;F&#039;,&#039;G&#039;,&#039;H&#039;,&#039;I&#039;,&#039;J&#039;,&#039;K&#039;,&#039;L&#039;,&#039;M&#039;,&#039;N&#039;,&#039;O&#039;,&#039;P&#039;,&#039;Q&#039;,&#039;R&#039;,&#039;S&#039;,&#039;T&#039;,&#039;U&#039;,&#039;V&#039;,&#039;W&#039;,&#039;X&#039;,&#039;Y&#039;,&#039;Z&#039;,&#039;2&#039;,&#039;3&#039;,&#039;4&#039;,&#039;5&#039;,&#039;6&#039;,&#039;7&#039;];while($l=fgets(STDIN)){$l=rtrim($l);$b=&#039;&#039;;while($i&lt;strlen($l)){$b.=str_pad(base_convert(&#039;&#039;.ord($l[$i++]),10,2),8,0,0);}foreach(str_split($b,5)as$b){$a.=TABLE[base_convert(str_pad($b,5,0),2,10)];}$a.=match(count_chars($b)[48]){8=&gt;&#039;======&#039;,16:&#039;====&#039;,24:&#039;===&#039;,32:&#039;=&#039;,0:&#039;&#039;};echo$a.PHP_EOL;};</code></pre>
  <h2>実行結果</h2>
  <div class="js-phper-token">
      </div>
  <div class="mt-3">
    ステータス: <span class="js-aggregated-execution-status" data-answer-id="456">失敗</span>
      </div>
  <div class="mt-3">
          <h3>テストケース 1</h3>
      <div>
        ステータス: <span class="js-testcase-execution-status" data-testcase-execution-id="1061">実行時エラー</span>
              </div>
      <h4>標準出力</h4>
      <pre><code class="js-testcase-execution-stdout hljs language-plaintext" data-testcase-execution-id="1061">
Parse error: syntax error, unexpected token &quot;:&quot;, expecting &quot;=&gt;&quot; in php.wasm code on line 6

</code></pre>
      <h4>標準エラー出力</h4>
      <pre><code class="js-testcase-execution-stderr hljs language-plaintext" data-testcase-execution-id="1061">
</code></pre>
          <h3>テストケース 2</h3>
      <div>
        ステータス: <span class="js-testcase-execution-status" data-testcase-execution-id="1062">実行時エラー</span>
              </div>
      <h4>標準出力</h4>
      <pre><code class="js-testcase-execution-stdout hljs language-plaintext" data-testcase-execution-id="1062">
Parse error: syntax error, unexpected token &quot;:&quot;, expecting &quot;=&gt;&quot; in php.wasm code on line 6

</code></pre>
      <h4>標準エラー出力</h4>
      <pre><code class="js-testcase-execution-stderr hljs language-plaintext" data-testcase-execution-id="1062">
</code></pre>
          <h3>テストケース 3</h3>
      <div>
        ステータス: <span class="js-testcase-execution-status" data-testcase-execution-id="1063">実行時エラー</span>
              </div>
      <h4>標準出力</h4>
      <pre><code class="js-testcase-execution-stdout hljs language-plaintext" data-testcase-execution-id="1063">
Parse error: syntax error, unexpected token &quot;:&quot;, expecting &quot;=&gt;&quot; in php.wasm code on line 6

</code></pre>
      <h4>標準エラー出力</h4>
      <pre><code class="js-testcase-execution-stderr hljs language-plaintext" data-testcase-execution-id="1063">
</code></pre>
          <h3>テストケース 4</h3>
      <div>
        ステータス: <span class="js-testcase-execution-status" data-testcase-execution-id="1064">実行時エラー</span>
              </div>
      <h4>標準出力</h4>
      <pre><code class="js-testcase-execution-stdout hljs language-plaintext" data-testcase-execution-id="1064">
Parse error: syntax error, unexpected token &quot;:&quot;, expecting &quot;=&gt;&quot; in php.wasm code on line 6

</code></pre>
      <h4>標準エラー出力</h4>
      <pre><code class="js-testcase-execution-stderr hljs language-plaintext" data-testcase-execution-id="1064">
</code></pre>
      </div>
  <script type="module" src="../../../../assets/loading.js"></script>
    </main>
    <footer class="container text-center mt-5 mb-4">
      Albatross.PHP - PHPerKaigi 2024
    </footer>
  </body>
</html>