あみだくじ
Posted feedbacks - Groovy
ロジック、ちょっと汚いですね
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 | def text = """\
A B C D E
| | |-| |
|-| | |-|
| |-| |-|
|-| |-| |
|-| | | |"""
def lines = text.split("\n")
def positions = lines[0].split(/\s+/)
lines[1..-1].each{
def sepa = it.split(/\|/)[1..-1]
(0..<(sepa.size())).each{ i ->
if( sepa[i].trim() == "-" ){
def temp = positions[i]
positions[i] = positions[i + 1]
positions[i + 1] = temp
}
}
}
println text
positions.each{ print it.padRight(2) }
|


greentea #4476() Rating4/6=0.67
[ reply ]