Perl, 103 + 2 = 105 바이트
s/$/$"x y===c/gem;$a=$_;$_.=$"while$a=~s/^./!($_.=$&)/gem;s/$1/-/g,$b="$&$b"while/\s(\w)(\1|-)+ /;say$b
-n0
(2 바이트 페널티)로 실행하십시오 .
설명:
# -n0: read entire input into `$_` at start of program
# (technically speaking it reads to the first NUL byte, but there aren't any)
# We want to be able to extract columns from the input, so we need to add spaces
# to the ends of each line such that each column is complete. Adding too many
# space is OK, so to ensure we have enough, we add a number of spaces equal to the
# length of the input.
s/$/ # At the end of {something},
$" x # append a number of spaces ($" is a space by default)
y===c # obtained by counting the characters in $_
/gem; # where {something} is each (g) line (m)
$a = $_; # store a copy of the transformed input in $a
# The next step is to create a transposition of the input. To do that, we
# repeatedly extract the first column of $a and append it to $_. This will lead to
# a bunch of junk whitespace at the end of $_ (of varying lengths, because once a
# line is empty it's omitted from the extracted column), but we're OK with that.
# To transpose properly, we'd want to place newlines between the extracted
# columns; however, it happens that the rest of the program treats space the same
# way it would newline, and separating via spaces is shorter, so we do that.
while ( # keep looping as long as there are matches
$a =~ s/^./ # replace the first character of {something related to $a}
!( # with the null string (NOT of something truthy)
$_.=$&) # but append that character ($&) to $_
/gem) { # {something} is each (g) line (m) of $a
$_.=$" # append a space ($", equivalent to newline here) to $_
}
# Finally, we repeatedly replace every character in the topmost line with the -
# character (treating a line as continuous through the - character but not through
# other characters), thus finding the lines from top to bottom. Because we
# appended the transpose of $_ to $_ above, each line appears twice: once
# horizontally, once vertically. We find only the horizontal copy, but replace
# both with hyphens.
# (Note: I rewrote the regex into a bit more readable of a form in this ungolfed
# version, because the original version wouldn't allow me room to write comments
# inside it. The two should be equivalent; I tested the golfed version.)
while ( # keep looping as long as there are matches
/\s(\w) # match a space or newline, $1 (a letter/digit/underscore),
(\1|-)+ # any positive number of $1s and hyphens,
\ /x) { # and a space
s/$1/-/g, # changes all $1s to spaces; set $& to $1, $1 becomes invalid
$b = "$&$b" # prepend $& to $b
}
# We need to output the lines from first (i.e. bottom) to last (i.e. top).
# We found them in the opposite order, but reversed them via prepending
# (not appending) the partial results to $b.
say $b # output $b
여기에 약간의 미묘함이 다음과 같은 입력으로 제공됩니다.
알파벳
DDDDDDDDD
알파벳
알파벳
알파벳
여기 네 번째 줄을보십시오. 서면 순서가 BACBD라면 문제의 가정을 위반하지 않고 실제로 가로 줄 이 생길 수 있습니다 B
(각 색상의 한 줄만, 우리가 확인하지 않는 것 제외). 이 문제를 해결하기 위해 마지막 정규 표현식에서 각 줄 은 문자 (또는 숫자 또는 밑줄로 시작하지만 불가능합니다)를 보장하고 평행선이 왼쪽에서 오른쪽으로, 위쪽에서 발견된다는 사실에 의존합니다. -to-bottom (정규 표현식이 문자열 내에서 첫 번째 일치 항목을 찾기 때문에). 따라서 여기에서 각 모호한 줄의 첫 문자는 줄 자체가 일치하는 것으로 표시되기 전에 덮어 쓰기되어 정규식 일치를 방지합니다.