调整椅子

18

例子

``````5,3,2,2,1

O
|
|
| _
| |
|_|_
|
|
O
``````

``````3,5,2,3,5

O
|  _
|  |
|__|__
|
|
__|__
OOOOO
``````

``````2,13,1,1,13

O
|      _
|______|______
______|______
OOOOOOOOOOOOO
``````

椅子零件

``````O
|
|  <- Backrest
|  _  <- Armrest
|  |
|__|__ <- Seat
|
|   <- Leg
_|_
OOO  <- Wheels
``````

输入值

1. 靠背高度
2. 座宽 始终为奇数
3. 扶手高度 始终小于靠背高度
4. 腿高
5. 车轮数始终小于或等于座椅宽度始终为奇数

详细部分说明

``````O
|
|
``````

``````__|__
``````

``````_
|
|
``````

``````|
|
``````

``````_ _
OOO
``````

输出量

@Doorknob冰哎呀，输入顺序有问题，我已经解决了。
Downgoat

“飞机”使我想起了超级马里奥兄弟3号的许多此类坦克
El'endia Starman 2015年

2

9

JavaScript（ES6），197个字节

``(b,s,a,l,w)=>eval('o="";for(i=0;i<b+l+2;i++)o+=(i?i>b?x[r](s/2-w/2+1)+(i>b+l?"O"[r](w):(p=(i<b+l?x:"_")[r](w/2))+"|"+p):"|"+(p=(i-b?x=" ":"_")[r="repeat"](s/2))+(i>b-a?"|":i<b-a?x:"-")+p:"O")+`\n`')``

说明

``````(b,s,a,l,w)=>
eval(
o="";
for(i=0;i<b+l+2;i++)                        // for each line
o+=(i?                                    // add to output

// Leg lines
i>b?
x[r](s/2-w/2+1)                       // spaces before wheels
+(
i>b+l?
"O"[r](w)                         // wheels
:
(p=(i<b+l?x:"_")[r](w/2))         // spaces or wheel cover before leg
+"|"                              // leg
+p                                // spaces or wheel cover after leg
)

// Backrest lines
:
"|"                                   // backrest
+(p=(i-b?x=" ":"_")[r="repeat"](s/2)) // spaces or seat before armrest
+(i>b-a?"|":i<b-a?x:"-")              // armrest
+p                                    // spaces or seat after armrest

:"O")
+\`\n\`
)``````

3

Python 2，157字节

``````b,s,a,l,w=input()
y,z,n,A='|_\n '
s/=2;W=w/2;x=A*s;X=n+A*(s-W+1);Y=n+y
print'O'+Y*(b-a-1)+Y+x+z+(Y+x+y)*(a-1)+n+(y+z*s)*2+(n+A+x+y)*(l-1)+X+z*W+y+z*W+X+'O'*w``````

`3,7,1,2,5`

``````O
|
|   _
|___|___
|
__|__
OOOOO
``````

3

JavaScript（ES6），182

``````(b,s,a,l,w,R=(x=s/2,c=' ')=>c.repeat(x),f=`
`+R(s/2+1-w/2),h=R(s/2,'_'),g=R(w/2,'_'),v='|')=>'O'+R(b+~a,u=`
`+v)+u+R()+'_'+R(a-1,u+R()+v)+u+h+v+h+R(l-1,`
`+R()+v)+f+g+v+g+f+R(w,'O')``````

``````(b, s, a, l, w, // parameters
// local variables as parameters with default values
R = (x=s/2,c=' ')=>c.repeat(x), // shortcut for repeat
f = `\n`+R(s/2+1-w/2), // filler before the wheels (used twice)
h = R(s/2,'_'), // half seat (used twice)
g = R(w/2,'_'), // last wheel support (used twice)
v = '|', // vertical bar (used many times)
u = `\n`+v // newline + bar (define below in the golfed version)
)=>
'O'+R(b+~a, u)+  // backrest
u+R()+'_'+       // backrest + armrest top
R(a-1, u+R()+v)+ // backrest + armrest
u+h+v+h+         // seat
R(l-1, `\n`+R()+v)+ // leg
f+g+v+g+         // wheels support
f+R(w, 'O')      // wheels``````

``````f=(b,s,a,l,w,R=(x=s/2,c=' ')=>c.repeat(x),f=`
`+R(s/2+1-w/2),h=R(s/2,'_'),g=R(w/2,'_'),v='|')=>'O'+R(b+~a,u=`
`+v)+u+R()+'_'+R(a-1,u+R()+v)+u+h+v+h+R(l-1,`
`+R()+v)+f+g+v+g+f+R(w,'O')

console.log=x=>O.innerHTML=x+'\n'

function test()
{
p=I.value.match(/\d+/g).map(x=>+x)
console.log(p+'\n'+f(...p)+'\n')
}``````
``````Input <input type="text" id="I" value="5,5,3,2,3" />
<button onclick="test()">Go</button>
<pre id="O"></pre>``````

1
+1表示函数参数中的字节多于函数主体。
user81655 2015年

1

SpecBAS - 185个 168字节

``````1 INPUT b's'a'l'w: sx=(s/2)+1,wx=sx-(w/2)
2  ?"o"'("|"#13)*b
3  ?AT b,1;"_"*s;AT b+l,wx;"_"*w;AT b-a,sx;"-"
4 FOR i=b+1-a TO b+l: ?AT i,sx;"|": NEXT i
5  ?AT b+l+1,wx;"0"*w
``````

1

Perl，181字节

``````(\$b,\$s,\$a,\$l,\$w)=/\d+/g;\$,=\$/;print'O',('|')x(\$b-\$a-1),(\$D='|'.\$"x(\$s/=2)).'_',("\$D|")x--\$a,(\$q='|'.'_'x\$s).\$q,(\$"x\$s.' |')x--\$l,(\$x=\$"x(1+\$s-(\$W=\$w/2))).'_'x\$W.'|'.'_'x\$W,\$x.O x\$w
``````

``````#!/usr/bin/perl -n              # -n: iterate stdin, put in \$_

(\$b,\$s,\$a,\$l,\$w)=/\d+/g;        # get the parameters

\$,=\$/;                          # set \$OUTPUT_FIELD_SEPARATOR to \n;
# this is printed between each of print's args

print                           # shorter than `-p` and @_=(...); \$"=\$/; \$_="@_";
'O',                        # the headrest

('|')x(\$b-\$a-1),            # space between headrest and armrest.
# (...) x \$n: produces \$n lists.

(\$D='|' . \$"x(\$s/=2))       # backrest and padding (\$"=' ') up to armrest
. '_',                      # armrest.

("\$D|")x--\$a,               # backrest, padding, armrest

(\$q='|' . '_'x\$s) . \$q,     # backrest bottom and 1/2 seat, armrest bottom and 1/2 seat

(\$" x \$s . ' |' ) x --\$l,   # padding before leg and leg, repeated leg-1 times

( \$x =
\$" x (1+\$s - (\$W=\$w/2) )  # padding before wheel top
)
. '_'x\$W . '|'              # left side of wheel top, wheel top,
. '_'x\$W,                   # right side of wheel top

\$x . O x\$w                  # padding before wheels, wheels
``````
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.