-
Notifications
You must be signed in to change notification settings - Fork 0
/
16a.php
39 lines (29 loc) · 876 Bytes
/
16a.php
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
<?php
include 'utilities.php';
$dancers = range('a', 'p');
foreach (explode(',', input()) as $move) {
$action = substr($move, 0, 1);
$info = substr($move, 1);
switch ($action) {
case 's':
for($i=0; $i < $info; $i++) {
array_unshift($dancers, array_pop($dancers));
}
break;
case 'x':
[$a, $b] = explode('/', $info);
$temp = $dancers;
$dancers[$a] = $temp[$b];
$dancers[$b] = $temp[$a];
break;
case 'p':
[$a, $b] = explode('/', $info);
$temp = $dancers;
$key1 = array_search ($a, $dancers);
$key2 = array_search ($b, $dancers);
$dancers[$key1] = $temp[$key2];
$dancers[$key2] = $temp[$key1];
break;
}
}
echo implode($dancers) . PHP_EOL;