All pastes #297053 Raw Edit

Stuff

public php v1 · immutable
#297053 ·published 2006-12-30 20:31 UTC
rendered paste body
#!/usr/bin/php<?php$input = stream_get_contents(STDIN);$input = explode("\n", $input);for ($j = 0, $max = sizeof($input); $j < $max; $j += 2){        if (intval($input[$j]) == 0)        {                exit;        }        $n = intval($input[$j]);        preg_match_all('/-?\d+/', $input[$j + 1], $b_raw, PREG_PATTERN_ORDER);        $b = array_combine(range(1, sizeof($b_raw[0])), $b_raw[0]);        $a = array_combine(range(1, sizeof($b_raw[0])), array_fill(1, sizeof($b_raw[0]), 0));        $stack = range($n, 1);        if (sizeof($b) !== $n)        {                echo '-1', "\n";        }        foreach ($b as $i => $value)        {                $a[$i] = intval(implode('', array_splice($stack, $b[$i], 1)));        }        echo ((empty($stack)) ? implode(' ', $a) : '-1'), "\n";/*print_r($a);print_r($b);print_r($stack);//*/}?>