1 PHP[ | ]
PHP
Copy
function allRotatedStrings($s) {
$res = [$s];
for($i=1; $i<strlen($s); $i++) {
$s = substr($s,1).substr($s,0,1);
$res[] = $s;
}
return $res;
}
print_r( allRotatedStrings('abcd') );
# Array
# (
# [0] => abcd
# [1] => bcda
# [2] => cdab
# [3] => dabc
# )
2 R[ | ]
R
Copy
s = "abcd"
n = nchar(s)
c(s, paste(substring(s, 2:n), substring(s, 1, 1:(n - 1)), sep = ""))
## [1] "abcd" "bcda" "cdab" "dabc"
3 같이 보기[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.