問題 #3 - 回答 #93

Brainf*ck

Brainf*ck を実装してください。標準入力から Brainf*ck のソースコードが渡されます。Brainf*ck の仕様のうち、入力命令である「,」は未実装で構いません。 一部明確に挙動が定められていない部分については、以下の仕様とします。 メモリの各セルは 8 bit の符号なし整数です。今回の入力でオーバーフローは発生しません。 メモリのアドレスは非負整数です。今回の入力で負のアドレスへポインタを動かすことはありません。 Brainf*ck に存在する命令以外の文字を受け取った場合は無視してください。 今回の入力に不正なプログラムは含まれません。すなわち、「[」と「]」は必ず釣り合っています。

回答 #93

tsbkw が 2024-03-09 11:48:35 に投稿

コード

327 byte

$p=0;for($s=stream_get_contents(STDIN);$p<strlen($s);)switch($s[$p++]){case'>':$p++;break;case'<':$p--;break;case'+':$m[$p]++;break;case'-':$m[$p]--;break;case'.':echo chr($m[$p]);break;case'[':if(!$m[$p])for($d=1;++$p;$d+=$s[$p]=='['?-1:($s[$p]==']'));break;case']':if($m[$p])for($d=-1;--$p;$d+=$s[$p]==']'?-1:($s[$p]=='['));}

実行結果

ステータス: 失敗

テストケース 1

ステータス: 時間制限超過

標準出力

標準エラー出力

Time Limit Exceeded: 10000 msec

テストケース 2

ステータス: 不正解

標準出力


Warning: Undefined variable $m in php.wasm code on line 6

Warning: Undefined array key 1 in php.wasm code on line 6

Warning: Undefined array key 2 in php.wasm code on line 6

Warning: Undefined array key 3 in php.wasm code on line 6

Warning: Undefined array key 4 in php.wasm code on line 6

Warning: Undefined array key 5 in php.wasm code on line 6

Warning: Undefined array key 6 in php.wasm code on line 6

Warning: Undefined array key 7 in php.wasm code on line 6

Warning: Undefined array key 8 in php.wasm code on line 6

Warning: Undefined array key 9 in php.wasm code on line 6

Warning: Undefined array key 10 in php.wasm code on line 6

Warning: Undefined array key 11 in php.wasm code on line 6

Warning: Undefined array key 12 in php.wasm code on line 6

Warning: Undefined array key 13 in php.wasm code on line 6

Warning: Undefined array key 14 in php.wasm code on line 6

Warning: Undefined array key 15 in php.wasm code on line 6

Warning: Undefined array key 16 in php.wasm code on line 6

Warning: Undefined array key 17 in php.wasm code on line 6

Warning: Undefined array key 18 in php.wasm code on line 6

Warning: Undefined array key 19 in php.wasm code on line 6

Warning: Undefined array key 20 in php.wasm code on line 6

Warning: Undefined array key 21 in php.wasm code on line 6

Warning: Undefined array key 22 in php.wasm code on line 6

Warning: Undefined array key 23 in php.wasm code on line 6

Warning: Undefined array key 24 in php.wasm code on line 6

Warning: Undefined array key 25 in php.wasm code on line 6

Warning: Undefined array key 26 in php.wasm code on line 6

Warning: Undefined array key 27 in php.wasm code on line 6

Warning: Undefined array key 28 in php.wasm code on line 6

Warning: Undefined array key 29 in php.wasm code on line 6

Warning: Undefined array key 30 in php.wasm code on line 6

Warning: Undefined array key 31 in php.wasm code on line 6

Warning: Undefined array key 32 in php.wasm code on line 6

Warning: Undefined array key 33 in php.wasm code on line 6

Warning: Undefined array key 34 in php.wasm code on line 6

Warning: Undefined array key 35 in php.wasm code on line 6

Warning: Undefined array key 36 in php.wasm code on line 6

Warning: Undefined array key 37 in php.wasm code on line 6

Warning: Undefined array key 38 in php.wasm code on line 6

Warning: Undefined array key 39 in php.wasm code on line 6

Warning: Undefined array key 40 in php.wasm code on line 6

Warning: Undefined array key 41 in php.wasm code on line 6

Warning: Undefined array key 42 in php.wasm code on line 6

Warning: Undefined array key 43 in php.wasm code on line 6

Warning: Undefined array key 44 in php.wasm code on line 6

Warning: Undefined array key 45 in php.wasm code on line 6

Warning: Undefined array key 46 in php.wasm code on line 6

Warning: Undefined array key 47 in php.wasm code on line 6

Warning: Undefined array key 48 in php.wasm code on line 6

Warning: Undefined array key 49 in php.wasm code on line 6

Warning: Undefined array key 50 in php.wasm code on line 6

Warning: Undefined array key 51 in php.wasm code on line 6

Warning: Undefined array key 52 in php.wasm code on line 6

Warning: Undefined array key 53 in php.wasm code on line 6

Warning: Undefined array key 54 in php.wasm code on line 6

Warning: Undefined array key 55 in php.wasm code on line 6

Warning: Undefined array key 56 in php.wasm code on line 6

Warning: Undefined array key 57 in php.wasm code on line 6

Warning: Undefined array key 58 in php.wasm code on line 6

Warning: Undefined array key 59 in php.wasm code on line 6

Warning: Undefined array key 60 in php.wasm code on line 6

Warning: Undefined array key 61 in php.wasm code on line 6

Warning: Undefined array key 62 in php.wasm code on line 6

Warning: Undefined array key 63 in php.wasm code on line 6

Warning: Undefined array key 64 in php.wasm code on line 6

Warning: Undefined array key 65 in php.wasm code on line 6

Warning: Undefined array key 66 in php.wasm code on line 6

Warning: Undefined array key 67 in php.wasm code on line 6

Warning: Undefined array key 68 in php.wasm code on line 6

Warning: Undefined array key 69 in php.wasm code on line 6

Warning: Undefined array key 70 in php.wasm code on line 6

Warning: Undefined array key 71 in php.wasm code on line 6

Warning: Undefined array key 72 in php.wasm code on line 6

Warning: Undefined array key 73 in php.wasm code on line 6

Warning: Undefined array key 74 in php.wasm code on line 6

Warning: Undefined array key 75 in php.wasm code on line 6

Warning: Undefined array key 76 in php.wasm code on line 6

Warning: Undefined array key 77 in php.wasm code on line 6

Warning: Undefined array key 78 in php.wasm code on line 6

Warning: Undefined array key 79 in php.wasm code on line 6

Warning: Undefined array key 80 in php.wasm code on line 6

Warning: Undefined array key 81 in php.wasm code on line 6

Deprecated: chr(): Passing null to parameter #1 ($codepoint) of type int is deprecated in php.wasm code on line 6

標準エラー出力


テストケース 3

ステータス: 時間制限超過

標準出力

標準エラー出力

Time Limit Exceeded: 10000 msec