blob: bc3dca6d8c69f0241ce4a9c42054449ad8b26fc8 (
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>問題 #2 - 回答 #159 | 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 - 回答 #159</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">#159</li>
</ol>
</nav>
<h2>Base32</h2>
<p>
RFC 4648 で定義された Base32 エンコーディングを実装してください。
標準入力から与えられる各行に対し、Base32 エンコードをおこなった文字列を標準出力へ改行区切りで出力してください。
なお、アルファベットの出力には大文字を用いてください。
</p>
<h2>回答 #159</h2>
<p>
zonepotage が 2024-03-09 16:57:29 に投稿
</p>
<h2>コード</h2>
<p>
808 byte
</p>
<pre><code class="hljs language-php">while ($plaintext = fgets(STDIN)) {
$text = '';
$bit = 0;
$value = 0;
$i = 0;
while(($bit >= 5) || ($i < strlen($plaintext))){
if($i < strlen($plaintext)){
$value = ($value * 256) + ord($plaintext[$i]);
$bit+= 8;
$i++;
}
$bit -= 5;
$code = (int)($value / pow(2,$bit));
$text .= chr($code + 65 - ($code > 25 ? 41 : 0));
$value %= (pow(2, $bit));
if(($bit < 5) && ($bit > 0) && ($i >= strlen($plaintext))){
$value *= pow(2,5 - $bit);
$bit = 5;
}
}
if(strlen($text) % 8){
$text .= str_repeat("=",8 - strlen($text) % 8);
}
echo $text, 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="582">失敗</span>
</div>
<div class="mt-3">
<h3>テストケース 1</h3>
<div>
ステータス: <span class="js-testcase-execution-status" data-testcase-execution-id="1274">不正解</span>
</div>
<h4>標準出力</h4>
<pre><code class="js-testcase-execution-stdout hljs language-plaintext" data-testcase-execution-id="1274">NBXWOZIK
OBUXS3YK
MZ2WOYIK
</code></pre>
<h4>標準エラー出力</h4>
<pre><code class="js-testcase-execution-stderr hljs language-plaintext" data-testcase-execution-id="1274">
</code></pre>
<h3>テストケース 2</h3>
<div>
ステータス: <span class="js-testcase-execution-status" data-testcase-execution-id="1275">実行時エラー</span>
</div>
<h4>標準出力</h4>
<pre><code class="js-testcase-execution-stdout hljs language-plaintext" data-testcase-execution-id="1275">
Deprecated: Implicit conversion from float 2346943114 to int loses precision in php.wasm code on line 21
Deprecated: Implicit conversion from float -17657853213 to int loses precision in php.wasm code on line 21
Deprecated: Implicit conversion from float -122363911295 to int loses precision in php.wasm code on line 21
Deprecated: Implicit conversion from float 8589934592 to int loses precision in php.wasm code on line 21
Fatal error: Uncaught DivisionByZeroError: Modulo by zero in php.wasm code:21
Stack trace:
#0 {main}
thrown in php.wasm code on line 21
</code></pre>
<h4>標準エラー出力</h4>
<pre><code class="js-testcase-execution-stderr hljs language-plaintext" data-testcase-execution-id="1275">
</code></pre>
<h3>テストケース 3</h3>
<div>
ステータス: <span class="js-testcase-execution-status" data-testcase-execution-id="1276">実行時エラー</span>
</div>
<h4>標準出力</h4>
<pre><code class="js-testcase-execution-stdout hljs language-plaintext" data-testcase-execution-id="1276">GEZDGNBVGY3QU===
GEZAU===
Deprecated: Implicit conversion from float 26696235312 to int loses precision in php.wasm code on line 21
Deprecated: Implicit conversion from float 237166473226 to int loses precision in php.wasm code on line 21
Deprecated: Implicit conversion from float 8589934592 to int loses precision in php.wasm code on line 21
Fatal error: Uncaught DivisionByZeroError: Modulo by zero in php.wasm code:21
Stack trace:
#0 {main}
thrown in php.wasm code on line 21
</code></pre>
<h4>標準エラー出力</h4>
<pre><code class="js-testcase-execution-stderr hljs language-plaintext" data-testcase-execution-id="1276">
</code></pre>
<h3>テストケース 4</h3>
<div>
ステータス: <span class="js-testcase-execution-status" data-testcase-execution-id="1277">実行時エラー</span>
</div>
<h4>標準出力</h4>
<pre><code class="js-testcase-execution-stdout hljs language-plaintext" data-testcase-execution-id="1277">MEQGEIDDBI======
Deprecated: Implicit conversion from float 3816916000 to int loses precision in php.wasm code on line 21
Deprecated: Implicit conversion from float -19301916445 to int loses precision in php.wasm code on line 21
Deprecated: Implicit conversion from float -268366191743 to int loses precision in php.wasm code on line 21
Deprecated: Implicit conversion from float 8589934592 to int loses precision in php.wasm code on line 21
Fatal error: Uncaught DivisionByZeroError: Modulo by zero in php.wasm code:21
Stack trace:
#0 {main}
thrown in php.wasm code on line 21
</code></pre>
<h4>標準エラー出力</h4>
<pre><code class="js-testcase-execution-stderr hljs language-plaintext" data-testcase-execution-id="1277">
</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>
|