Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $number=readline();
- $arr=explode(" ",readline());
- $position=0;
- for($i=1;$i<=$number;$i++)
- {
- $command=explode(" ",readline());
- switch ($command[0])
- {
- case "Forward":
- if($command[1]+$position>=0&&$command[1]+$position<count($arr)&&$command[1]>=0&&$command[1]<count($arr))
- {
- $position += $command[1];
- array_splice($arr, $position, 1);
- }
- break;
- case "Back":
- if($position-$command[1]>=0&&$position-$command[1]<count($arr)&&$command[1]>=0&&$command[1]<count($arr))
- {
- $position -= $command[1];
- array_splice($arr, $position, 1);
- }
- break;
- case "Gift":
- if($command[1]>=0&&$command[1]<count($arr))
- {
- $position = $command[1];
- array_splice($arr, $position, 0, $command[2]);
- }
- break;
- case "Swap":
- $index1=array_search($command[1],$arr);
- $index2=array_search($command[2],$arr);
- if($index1!==false && $index2!==false)
- {
- $temp = $arr[$index1];
- $arr[$index1] = $arr[$index2];
- $arr[$index2] = $temp;
- }
- break;
- }
- }
- echo "Position: {$position}".PHP_EOL;
- echo implode(", ",$arr);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement