<?php
$cofre = [];
while (($linha = fgets(STDIN)) !== false) {
$linha = trim($linha);
if ($linha === "") continue;
$partes = explode(" ", $linha);
$operacao = intval($partes[0]);
if ($operacao == 0) break;
if ($operacao == 1) {
$x = intval($partes[1]);
$cofre[] = $x;
} elseif ($operacao == 2) {
$k = intval($partes[1]) - 1;
$tamanho = count($cofre);
if ($k >= 0 && $k < $tamanho) {
for ($i = $k; $i < $tamanho - 1; $i++) {
$cofre[$i] = $cofre[$i + 1];
}
array_pop($cofre);
}
} elseif ($operacao == 3) {
$tamanho = count($cofre);
if ($tamanho == 0) {
echo "Cofre vazio!" . PHP_EOL;
} else {
for ($i = 0; $i < $tamanho; $i++) {
echo $cofre[$i] . ($i < $tamanho - 1 ? " " : "");
}
echo PHP_EOL;
}
}
}
?>
To embed this project on your website, copy the following code and paste it into your website's HTML: