Python,672个字符
可读性较低的版本:
import sys
r=range
M=[0,0,0,191,0,196,218,194,0,217,179,180,192,193,195,197]
Z=[map(int,l.split(",")) for l in sys.stdin.readlines()]
S=[[[0]*5 for x in r(77) ] for y in r(58)]
for i in r(len(Z)):
A,C,B,D=Z[i]
for a,b,c in [(C,A,2),(C,A,3),(D,A,1),(D,A,2),(C,B,3),(C,B,4),(D,B,1),(D,B,4)]:S[a][b][c]=1
for x in r(A+1,B):
for a,b in [(C,2),(C,3),(C,4),(D,1),(D,2),(D,4)]:S[a][x][b]=(b+1)&1
for y in r(C+1,D):
for a,b in [(A,1),(A,2),(A,3),(B,1),(B,3),(B,4)]:S[y][a][b]=b&1
for x in r(A+1,B):
for y in r(C+1,D):S[y][x]=[i+1]+[0]*4
O=sys.stdout.write
for l in S:
for k in l:
c=' ';x=M[k[1]*8|k[2]*4|k[3]*2|k[4]]
if k[0]:c=':'
if x:c=chr(x)
O(c)
O('\n')
从以下版本开始:
import sys
coords = [ tuple(map(int,l.strip().split(","))) for l in sys.stdin.readlines() ]
screen = [ [ [-1, [False,False,False,False]] for x in range(0, 77) ] for y in range(0, 58) ]
def mergeBorders(screen, w):
x0,y0,x1,y1 = w
screen[y0][x0][1][1] = True
screen[y0][x0][1][2] = True
screen[y1][x0][1][0] = True
screen[y1][x0][1][1] = True
screen[y0][x1][1][2] = True
screen[y0][x1][1][3] = True
screen[y1][x1][1][0] = True
screen[y1][x1][1][3] = True
for x in range(x0+1,x1):
screen[y0][x][1][1] = True
screen[y0][x][1][2] = False
screen[y0][x][1][3] = True
screen[y1][x][1][0] = False
screen[y1][x][1][1] = True
screen[y1][x][1][3] = True
for y in range(y0+1,y1):
screen[y][x0][1][0] = True
screen[y][x0][1][1] = False
screen[y][x0][1][2] = True
screen[y][x1][1][0] = True
screen[y][x1][1][2] = True
screen[y][x1][1][3] = False
def paintInside(screen, w, wId):
x0,y0,x1,y1 = w
for x in range(x0+1,x1):
for y in range(y0+1,y1):
screen[y][x][0] = wId
screen[y][x][1] = [False, False, False, False]
for wId in range(len(coords)):
w = coords[wId]
mergeBorders(screen, w)
paintInside(screen, w, wId)
borderMap = { (False, True, True, False): 0xda,
(False, True, False, True): 0xc4,
(False, True, True, True): 0xc2,
(False, False, True, True): 0xbf,
(True, False, True, False): 0xb3,
(True, True, True, False): 0xc3,
(True, True, True, True): 0xc5,
(True, False, True, True): 0xb4,
(True, True, False, False): 0xc0,
(True, True, False, True): 0xc1,
(True, False, False, True): 0xd9 }
def borderChar(c):
return chr(borderMap[(c[0],c[1],c[2],c[3])])
for screenLine in screen:
for contents in screenLine:
c = ' '
if True in contents[1]:
c = borderChar(contents[1])
elif contents[0] >= 0:
c = ':'
sys.stdout.write(c)
sys.stdout.write('\n')
javascript:$('pre').css('line-height','1em')