함수 allRotatedStrings()

1 PHP[ | ]

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[ | ]

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 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}